Overlooked Optimizations: Images
#1 This guest post from Billy Hoffman is the last post in the Velocity countdown series. Velocity starts first thing tomorrow! Hope you enjoyed the ride and please welcome Billy Hoffman!
Billy Hoffman (@zoompf) is the founder and CEO of Zoompf, a web performance startup whose scanning technology helps website owners find and fix performance issues which are slowing down their sites. Previously Billy was a web security researcher at SPI Dynamics and managed a research team at HP. He can open a Coke can without using his hands.
(tl;dr: Images make up the majority of the Internet, yet we consistently fail to apply the most basic of optimizations. Even big sites like Twitter are completely screwing this up. Furthermore, there are huge unexplored areas when it comes to image optimization which would provide significant savings. We should stop worrying about esoteric performance optimizations when there is so much other low hanging fruit.)
Images constitute the bulk of content on the Internet, both in terms of content size and number of resources. Using data from the wonderful HTTP Archive we see that 60% of the bytes that make up an Alexa Top 1000 website are images. The average webpage references 81 external resources, and 64% of these are images. And the dominance of images is growing. In the last 6 months, total page content size increased by 70 kB. 75% of that increase (52 kB) came from images.



We know that lossless image optimization tools reduce content size anywhere from 5-20%. Occasionally you will see 70% savings or more, but that only happens when the image contains an embedded thumbnail. That level of savings doesn't sound all that impressive. After all HTTP compression can save 60-70% on real world text resources like HTML, JavaScript, or CSS. However text resources only make up on average 188 kB, or 24% of total content size. Saving 66% on 24% of content saves about as much as 5-20% savings on 60% of the content. In fact, if you could reduce images by 25%, that would have more of an effect on reducing total content size than using HTTP compression!
If you work in front-end performance, none of this should be a surprise. Obviously any front-end performance strategy needs to include image optimizations. Image optimization is an old topic. Shouldn't we instead be focusing on more esoteric optimizations, like refactoring CSS rules so that external fonts render faster on Blackberry Webkit? No, we shouldn't, because sadly we collectively suck at optimizing images.
Give PNG a Chance? Nope.
One of the most basic image optimizations that you can make is converting GIFs to PNGs. PNGs can do everything that GIFs can do and more, and the browser issues with PNGs are larger a problem of the past. Even without applying additional lossless optimization tools on the PNG, converting a GIF file will almost without exception create a smaller PNG. This is because the fundamental way graphics data is compressed in a file PNG, using the DEFLATE algorithm, is more efficient than GIF's LZW compression scheme. Once you apply lossless tools on the converted PNG they get even smaller. Animated GIFs are the exception here, as PNGs are not animated and alternatives for simple animations (MNG, Flash) are either not widely supported or result in larger files. So what is the break down of image formats on the web today?

37% of images on the Alexa Top 1000 websites are GIFs. That makes no sense given what we know about PNGs over GIFs. 37% of the images on the Internet are not animated "Under construction" icons or Ajax status thumper animations. People are not being intelligent about file formats they use for images.
The Internet, now with more bloat!
Applying lossless image optimization tools is one of the simplest optimizations to do. Take an image, run a program, get an optimized image. Stoyan and I love optimizations like this because they are so easy to automate. Just add a step to the website build process or to your staging-to-production publishing process that automatically optimizes images. It should be transparent, something you setup once and forget about. So how are we doing?
82% of Alexa Top 1000 websites contain images which were not losslessly optimized. Apply lossless optimizations across all the images from the Alexa top 1000 would reduce file size by an additional 15%.
Surely there are just a few number of smaller sites which aren't properly optimizing images which are pulling down the statistics right? Sadly no. Twitter, the ninth largest website in the world by traffic, doesn't losslessly optimize any of their images. 33% of total page load bytes could be eliminated solely by applying lossless image optimization. Let me phrase that a different way: 1 byte of our every 3 bytes Twitter sends you is unnecessary! This is an incredible waste.
Unplowed Fields
It's clear we are not applying the image optimizations we already know about. However there is much more work to be done with images. This is a largly unresearched or unadvocated area which needs more attention.
Consider choosing the correct image format. Are people saving images as a PNG when they should be saved as a JPEG? Indeed they are. Tumblr's background image is a 76 kB PNG image and it would be 33 kB (55% smaller) if it was a JPEG. This is better than their old 827 kB PNG background image, which would be 47 kB (94% smaller) if it was a JPEG. Unfortunately I know of no other tool besides Zoompf's free performance scan which identifies PNG candidate images for conversion to JPEG.
What about JPEGs saved with a high quality setting? This is a large enough topic for its own blog post. To quickly summarize, JPEG "quality" is an arbitrary, non-linear scale, quality is not a percentage of anything, and "quality of 80" does not mean "discard 20% of graphics data." Thought leaders like Adobe recommend a quality setting of 70-80 for JPEGs published on the web. Zoompf found that 36% of Alexa Top 1000 images have a quality setting over 80, and reducing them to quality 70 would on average reduce image size by 48%! While all of these images might not be able to be reduced in quality, surely some of them can. Again, this is an area that needs more attention, more best practices and guidance, and more tools to help validate.
Not "Instead of" but "In addition too"
I am not saying other performance optimizations are not important. Zoompf checks for over 380 performance issues and we are adding more all the time. Many of them are esoteric and low impact. We flag things like duplicate cookies, unnecessary HTTP headers, and even when your <META> contains duplicate keywords. However these checks are for when you have handled all the other important checks. Image optimizations, and research into new image optimization techniques should be not done instead of other work, but in addition to it. Just remeber to prioritize what you are working on so that it will affect the most number of people in the largest possible way.
Conclusions
Images are a huge component of the web and modern web performance. This importance is only growing. Sadly, there are only one or two widely recognized image optimizations techniques. Unfortunately, these most basic optimizations are ignored, forgotten, and not uniformly applied by even the largest of websites today. Additionally, there are a lot of unexplored areas of image optimization, including lossy image optimization, with no clear recommendations or best practices and virtually no tool support. Some areas for further research include:
- Lossy image optimizations
- Comparison of JPEG encoders
- PNG-to-JPEG and GIF-to-JPEG best practices, recommendations, and processes
- Image quality for Desktop vs. mobile browsing experiences
- Better PNG24 to PNG8 conversion guidelines. (I converted all the figures in this blog post from PNG24 to PNG8 and reduced file size by 52%)
- Viablility of WebP and automated delivery to supported browsers
I will be discussing many of these topics this week during my presentation Take it all Off! Lossy Image Optimization at Velocity 2011 on Wednesday. I hope you all can make it.
This entry was posted on Tuesday, June 14th, 2011 and is filed under images, performance. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
Get notification for future posts: follow me on Twitter or subscribe to my RSS feed

June 14th, 2011 at 7:21 am
In paragraph preceding “Conclusions,” I recommend changing:
‘be not done’
To:
‘not be done’
for better readability. Great article!
June 14th, 2011 at 12:28 pm
[...] Optimizations. I feel that this is such an important topic that I guest blogged about it over on phpied.com today. Images are the dominate content on the web, but rarely do anything to optimize them beyond a [...]
June 21st, 2011 at 1:49 pm
[...] Overlooked Optimizations: Images / Stoyan’s phpied.com. This entry was posted in front-end optimalisatie. Bookmark the permalink. ← 8 Ways to Speed Up the Performance of CakePHP Apps | PseudoCoder.com [...]
June 23rd, 2011 at 5:21 pm
I have added a couple of corrections I noticed while reading this truly needed article.
You wrote: “Consider choosing the correct image format. Are people saving images as a PNG when they should be saved as a JPEG? Indeed they are. Tumblr’s background image is a 76 kB PNG image and it would be 33 kB (55% smaller) if it was a JPEG. This is better than their old 827 kB PNG background image, which would be 47 kB (94% smaller) if it was a JPEG.”
One of the main problems with the suggestion in this paragraph is that the Tumblr’s background is a gradient image and will not resolve very well as a jpg image. So using the png image format was the best solution in this scenario. Now could it have been optimized better probably.
“Thought leaders like Adobe recommend a quality setting of 70-80 for JPEGs published on the web.” should be “Though leaders like Adobe recommend a quality setting of 70-80 for JPEGs published on the web.”
July 6th, 2011 at 3:19 pm
Great article! I’m working in many mobile sites and image optimization is a critic point that too many times is forgotten by developers. I will use in a couple of sites where we need low bandwidth access.
Thanks!
August 4th, 2011 at 1:49 am
[...] article: Overlooked Optimizations: Images / Stoyans phpied.com. Share [...]
September 9th, 2011 at 4:29 pm
When creating small (48×32) images in Photoshop, if I save as PNG, I get file sizes of ~5KB. When I save them as GIF, I get file sizes < 1KB.
See:
http://fx.asrar.ca/images/currency/48/eur.gif (681 B)
http://fx.asrar.ca/images/currency/48/eur.png (5.44 KB)
The GIF is using less colors (32, I think) than the PNG, but it looks virtually identical… is there a way to limit the number of colors a PNG uses?
Thanks in advance.
September 19th, 2011 at 6:03 am
In your conclusions, you mention further research of lossy image optimizations. What I find curious is that those optimizations already exist for JPEG images. For instance, the following two papers:
* http://ieeexplore.ieee.org/iel5/83/4711346/04682736.pdf?arnumber=4682736
* http://ieeexplore.ieee.org/iel5/4378863/4379219/04379276.pdf?arnumber=4379276
present a compression method fully compatible with existing JPEG decoders, that achieves a 30% reduction on file size without noticeable degradation and the method is quick (0.2 seconds to encode typical images).
On the other hand, the aforementioned algorithm can be adapted for arithmetic encoding and the gains are an astounding 40-45% file size reduction without noticeable degradation and quick (10% slower than the first algorithm):
* http://ieeexplore.ieee.org/ielx5/5075165/5090078/05090215.pdf?arnumber=5090215
I do not know if such a compressor is already available on the market, as I haven’t found one, but I’m eagerly waiting for that moment.
I also think that it is time for browsers start to support arithmetic encoded JPEGs and advertise it to web server by sending the HTTP header:
Accept-Encoding: gzip,deflate,jpeg
That way servers could start to send arithmetic encoded JPEGs now. After all we did not had to wait 10 years to start using gzip compression.
September 27th, 2011 at 4:55 pm
Asrar, try saving as PNG8
October 18th, 2011 at 11:22 am
Anyone know of a tool to mass convert PNGS to JPGS?
January 19th, 2012 at 10:40 am
robfaraj, you can use ImageMagick’s “convert” command with wildcards.
February 2nd, 2012 at 9:03 pm
I am curious to find out what blog system you are working with? I’m experiencing some minor security problems with my latest website and I’d like to find something more safeguarded. Do you have any solutions?
February 21st, 2012 at 3:18 pm
[...] weight. And images are contributing the largest portion of total page weight.We at Zoompf have made posts and given presentations all about this in the past. There is a lot that can be done to make sure [...]
May 18th, 2012 at 11:03 am
[...] nice enough to have me to contribute the final blog post in his Velocity Countdown series. My post, Overlooked Optimizations: Images looks at how images make up the largest amount of content on the web and yet we consistently forget [...]
August 3rd, 2012 at 4:16 am
We found similar discrepancies with another coachbuilt Ford we wrote about a few years back:
August 3rd, 2012 at 4:17 am
The next occasion Someone said a weblog, I genuinely hope so it doesnt disappoint me about this spot. What i’m saying is, Yes, it was my method to read, but I really thought youd have something intriguing to convey. All I hear can be a number of whining about something you could fix should you werent too busy searching for attention.