Dynamic CSS Sprites Theory

December 30, 2007

Update on September 23, 2009: My “theory” has been turned into a reality with Sprite Me

I thought of a way to optimize images and reduce http requests: dynamically stacking images together into a, ‘sprite’.


Because it would be painful to stitch the images together and write the CSS rules, this would have to be done dynamically with a server side language. CSS sprites are not a new theory , but dynamic sprites are. I would love for the day that PHP generates nicely written CSS classes for me to use. If no one else creates this, I will – in time.


Each http request ( test here ) takes on average 80-100ms per http request. If you have 40 images and compress them into 3 images, you would save 37 http requests, or at least 2 seconds of load time!


The limitations:


I’ve been sharing this theory with others in hopes that someone will care enough to build it (I don’t have time right at the moment). Recently I shared my theory with Pamela Fox (Google Maps) and she said she would try it out on Google docs. I am excited to see if anything becomes of that. Otherwise, it will remain a theory until someone builds it – and if no one else, I’ll build it when I get time.

4 comments

#1. Mark Figueredo on February 04, 2009

I already built this a couple years ago in ASP.net actually. I had a specific scenario where I was returning 10-20 or more images at a time for a query and I dynamically returned a new sprite and it resulted in huge speed advances.

#2. Marc Grabanski on February 05, 2009

Cool. :)

#3. Sam on April 28, 2009

Hey there,

do you have an idea how to sort the images more efficient? I found the k-sort algorithm and region quadtree would be an approach. But I lack the knowledge of alternate ways.
It would be great to have them stacked and piled by an algorithm that stores the sprites positions into the css as well.

Cheers

#4. John on January 17, 2011

Images loads in parrallel so the next image does not have to wait for the http request to finish. The amount of parrallel image downloads is limited to X (believe its 5 in FF), so if amount of images is bigger than X you will save http request time.

Leave a comment

Comment in textile images by gravatar