Serving WebP files with WP-Rocket

WebP is a new image format created by Google that can be used on your site in place of more traditional image types such .jpg’s and .png files.

There are now a number of WordPress plug-ins that allow you to utilise WebP files for you website such as WP-Rocket. However as this is such a new format not all browsers support the new file type. So for compatibility reasons you might still want to serve jpg files to users with browsers that don’t support the new WebP image type but serve WebP files to those that do.

What WP-Rocket does, is instead of changing all your images to WebP format, it maintains a copy for the .jpg as well. This means that the WebP’s get served to the users with browsers that support this and jpg’s get served to anyone else.

In order for this to work on STORM we’ve had to make some adjustments to the Nginx config. As you may be aware, STORM has a feature that allows you to server static files from Nginx. Details of this can be found here. So in order to use this feature alongside WP-Rockets WebP functionality the below config is now included by default in your websites Nginx config:

location ~* ^(/wp-content/.+).(png|jpg)$ {
    set $base $1;
    set $webp_uri $base$webp_suffix;
    set $root /sites/storm/websitename/public;
    root $root;
    add_header Vary Accept;
    if ( !-f $root$webp_uri ) {
        add_header X_WebP_SP_Miss $root$webp_uri;
    }
    try_files $webp_uri $uri =404;
}

Nimbus Hosting
1 Centrus, Mead Lane Hertford Hertfordshire SG13 7GX GB 0203 005 9181 [email protected]
×