Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the advantages of using CSS Sprites in web applications?

I'm working on a website with reasonably heavy traffic and I'm looking into using a CSS sprite to reduce the number of image loads in its design.

Are there any advantages to using a CSS sprite besides reducing the amount of transmitted data? How much space do you really save? Is there a threshold where using sprites becomes worthwhile to a website?

UPDATE: Thank you for your responses. They are obviously all very carefully thought out and present good sources to verify your points. I feel much more capable to make an informed decision about using CSS sprites in my site design now.

like image 287
Dean Putney Avatar asked Jul 28 '09 04:07

Dean Putney


People also ask

What are image sprites and why are they useful in CSS?

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

The question is generally not about the amount of bandwith it might save. It is more about lowering the number of HTTP requests needed to render a webpage.

Considering :

  • web browsers only do a few HTTP requests in parallel
  • doing an HTTP request means a round-trip to the server, which takes lots of time
  • we have "fast" internet connection, which means we download fast...

What takes time, when doing lots of requests to get small contents (like images, icons, and the like) is the multiple round-trips to the server : you end up spending time waiting for the request to go, and the server to respond, instead of using this time to download data.

If we can minimize the number of requests, we minimize the number of trips to the server, and use our hight-speed connection better (we download a bigger file, instead of waiting for many smaller ones).

That's why CSS sprites are used.


For more informations, you can have a look at, for instance : CSS Sprites: Image Slicing’s Kiss of Death

like image 160
Pascal MARTIN Avatar answered Sep 19 '22 17:09

Pascal MARTIN


Less http requests = faster loading overall. Yahoo and co. use this technique, if you can imagine the amount of users they have it saves a lot of bandwidth. Imagine 50 seperate images for icons, that's 50 seperate http requests as opposed to having just one css sprite containing all the images, that would save 49 http requests and multiply that per all the users of the site.

like image 26
meder omuraliev Avatar answered Sep 19 '22 17:09

meder omuraliev