Using WebP Images Today

Michael Walsh
By Michael WalshPublished

How to implement file size saving WebP images using Accept Content Negotiation.

Google Chrome Canary (the developer/early adopter version of Google Chrome) has recently added an “image/webp” accept header to image requests, which means that rather than needing to employ some sophisticated client side detection and fallback to use WebP. It’s possible to more simply deploy WebP using image request headers, at least for browsers that send the image/webp Accept header.

Configuring Nginx to negotiate based on this header is actually very straightforward as this Nginx configuration example shows (source):

location / {
# check Accept header for webp, check if .webp is on disk
if ($http_accept ~* "webp") { set $webp T; }
if (-f $request_filename.webp) { set $webp "${webp}T"; }
# if WebP is supported, and WebP is on disk, serve it!
if ($webp = TT) {
add_header Vary Accept;
rewrite (.*) $1.webp break;
}
# ...
}

This Nginx configuration code firstly checks to see if the user agent has sent the Accept header for WebP. If so, it then checks to see if a WebP image exists and then if both conditions are met the request is rewritten to serve the WebP image and the Vary: Accept header is added.

We use cookies to make this website work, to understand how it's used, and to measure our advertising. Find out more about cookies.

Cookie preferences

make an enquiry

Quick form · 3 steps · 1 min

How can we help?

Pick the closest match. We reply within one business day.

I am looking for

Website

New marketing website, microsite or redesign

E-commerce

Shopify store, new or rebuilt

Web application From £10,000 + VAT

Bespoke software and internal tools

AI implementation From £10,000 + VAT

Practical AI in your existing systems

Data visualisation From £10,000 + VAT

Dashboards and data pipelines

Migrations, hosting & support

Website migrations, web hosting and ongoing support

Something else / not sure yet

Let's talk it through

Prefer to talk?Book a call

Step 1 of 3

We'll be in touch within one business day to discuss your project. In the meantime, feel free to drop us a line at hello@enovate.co.uk if anything else comes up.

book directly

Book a discovery call with Michael

Michael Walsh, Founder & Managing Director. Pick a time that suits you, add your name and email, and the calendar invitation is yours.

Loading available times…

You can still book through the full calendar, orsend us a message.

Times shown in . The calendar invitation lands in your inbox the moment you confirm.

Booking is handled by Calendly; see our privacy policy.

You're booked in

(). The calendar invitation is on its way to .

RescheduleCancel