Why new image formats could make your site faster
Stage 3: Sell
Alex Painter
20th April 2015
Share this:

Image files are big, typically making up the majority of page weight on a website. This is especially true for retail sites, which often rely on lots of high-quality product pictures. This, in turn, tends to make those pages slow to load.

When it comes to image formats on the web, it’s a bit of an exclusive club, with only a handful of file types represented: JPEG, PNG, GIF or (occasionally) SVG.

This is despite the fact that there are a number of newer formats that would, on the face of it, result in much smaller file sizes – and make your site faster.

Why is this?

Browser support is the main problem. This is partly down to the fact that two of the more promising new formats have been developed by browsers vendors – Microsoft, which developed JPEG XR, and Google, which developed WEBP.

You won’t be surprised to learn that JPEG XR is supported by Internet Explorer (versions 9 and above) – and no other browser. WEBP enjoys slightly wider support – it works in Chrome (as you might have guessed) and Opera, but not Internet Explorer or Firefox.

The fact that there’s no longer a single browser that completely dominates the market is something of a double-edged sword. On the one hand, the increased competition means that when one browser vendor adopts a feature, it puts pressure on the others to do so. On the other, that pressure doesn’t amount to much when web developers are reluctant to use features that work in only one browser.

At the moment, Microsoft and Google are, it seems, tenaciously sticking to their own formats, each waiting for the other to blink first. So far, neither of them has. Mozilla has also weighed in with mozjpeg (an alternative to JPEG, which offers better compression). Another very promising new image format is BPG (Better Portable Graphics: http://bellard.org/bpg/), which you can use now, as long as you include a JavaScript decoder (which will incur a performance penalty, so it’s only really worth considering if you use lots of very large images).

Are the new formats really that much better anyway?

It depends who you ask. Mozilla conducted a study in 2014, the results of which failed to impress enough to persuade it to introduce support for JPEG XR or WEBP. However, Google’s own study on WEBP concluded that the average file size of a WEBP image would be 25–34% smaller than the equivalent JPEG.

While people argue about the relative benefits of each format, just having the option to use one of the new ones would be helpful. Maybe WEBP (for example) won’t be the ideal format on every occasion, but sometimes it will. Being able to pick and choose from a wider range of formats will help developers keep file sizes down while maintaining quality.

Isn’t it all academic without comprehensive browser support?

First, it’s worth saying that it’s always been possible to get around the support issue through server-side browser sniffing – i.e. detecting the browser in use and serving the most appropriate image. However, this isn’t always easy to maintain. Browsers change what they support from time to time, and they don’t have to tell you when they do it. So it’s up to you to update your code every time things change.

Fortunately, there is another way.

If you’ve been involved in commissioning or building a website in the last few years, you will almost certainly have heard of responsive design – building a website that adapts to the conditions in which it is viewed (primarily viewport width and screen resolution). The main reason for doing this is to ensure a decent user experience regardless of the device on which the site is viewed.

However, one of the difficulties with responsive design has, historically, been delivering the most appropriate image. The workarounds in use so far have involved loading bigger images than the user necessarily needs, loading more images than they need or using JavaScript to select the most appropriate image. None of these is ideal from a performance point of view.

Now a new specification, which makes use of the <picture> and <source> HTML elements, along with the srcset and sizes attributes, effectively solves the problem. Commonly known as the picture specification (in fact, this is a little misleading), it allows you to specify a number of different image sources and use a CSS media query to point the browser in the direction of the one that’s best for the end user’s viewport. At the time of writing, only Chrome fully supports the new spec, but people are already starting to use it. The details are beyond the scope of this article, but if you’re interested, you can read more about it here.

What has all this got to do with formats?

While the picture specification is primarily about size and resolution, it also allows you to specify multiple formats. The browser will then run through them in the order in which they’re given and pick the first one it supports (with a fallback for browsers that either don’t support the format or don’t support the picture specification).

This should open the way for developers to start using new types of image file much sooner than they might otherwise have done. This, in turn, might just encourage browser vendors to adopt those formats a bit more speedily.

The drawbacks

There are two problems with starting to use new image formats, using either browser sniffing or the picture specification.

One is the complexity that it introduces. In particular, if you’re building a responsive site, catering for different viewport sizes and screen resolutions, and you’re specifying several different formats, you find that the volume of HTML needed just to display one image is getting out of hand.

The other issue is the one that Facebook encountered when it trialled WEBP.

Using a new format is fine as long as all the end user wants to do is view the image on your website. But what if they want to download it and email it to a friend? Browser support isn’t the only issue you need to consider – if people need to download your images, you also need to think about whether they’ll be able to open those images in other applications. You could get around this with JavaScript (for example, by creating an alternative context menu that points to the JPEG version of the image when someone right-clicks on it). But you then have to ask whether the saving you make in terms of file size is really worth the extra complexity.

As things stand, then, we’re perhaps not quite at the point where website owners should be routinely adopting newer, more efficient formats. However, sites that depend on lots of high-quality graphical content might well benefit from minimising page size by selectively serving different file types.

  • Was this Helpful ?
  • Yes   No
Author: Alex Painter
Alex Painter is part of the professional services team for NCC Group’s website performance division.
Now read...
Six ways to win at Google’s new mobile ranking system
This week Google overhauled the way its search engine recommends websites on mobiles, introducing a new algorithm which would prioritise and favour those that are ‘mobile friendly’. This move,...
Featured eBooks
Copyright eSeller Publishing Limited © 2017
Connect with us
eSeller Media is the UK's leading channel for learning about selling in the digital age
eSeller partners