Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

when not to use CSS sprites?

Tags:

css

I want to know when not to use CSS sprites. CSS sprites works great, but are there any occasions when they create a lot of headaches?

like image 811
Gaurav Mishr Avatar asked Jul 25 '09 16:07

Gaurav Mishr


People also ask

Where are CSS sprites used?

CSS Sprites are a collection of images that are combined into a single file that an HTML document can access. These images are then called into use within the HTML code to be displayed on the website.

Which of the following is a benefit of using image sprites?

The main advantage of using image sprite is to reduce the number of http requests that makes our site's load time faster. The images also load faster making switching from one image to another on some event much smoother. Image Sprite are a collection of images placed into a single image.

What other performance benefit can you gain through accessing images using sprites?

An image sprite is a collection of images put into a single image. A web page with many images can take a long time to load and generates multiple server requests. Using image sprites will reduce the number of server requests and save bandwidth.


2 Answers

Like all things, there are times when it is useful, and there are times when it is harmful.

Many developers like to use CSS sprites because it saves on request time -- the browser makes one request, downloads the image, and all the various sprites are now automatically cached and blazing fast.

So how can it hurt?

Because download size != memory size.

That PNG or GIF that's only 10kb might actually be much, much greater in size once the browser loads it in memory. The issue is that while something like GIF will compress solid areas of color, the browser expands it out to a bitmap, where all images of equal dimensions use equal memory.

And it loads a new bitmap every time you use that image somewhere.

So everything in moderation.

See: http://blog.mozilla.com/webdev/2009/06/22/use-sprites-wisely/ for more info.

like image 51
thedz Avatar answered Oct 12 '22 22:10

thedz


Maintainability of your site will suffer from using them. Only combine images that belong to the same logical unit and are unlikely to be updated separately. Keep images that are likely to change separate to begin with.

like image 44
Thorarin Avatar answered Oct 13 '22 00:10

Thorarin