More from this category
Extra advice for webp – cloudfront / s3 bucket
https://www.keycdn.com/support/wordpress-cache-enabler-plugin
https://wordpress.org/plugins/webp-express/
https://developer.wordpress.com/docs/photon/api/ – possible reason for jetpack
https://support.cloudflare.com/hc/en-us/articles/360000607372 – cloudflare can create – have to sort out with cloudfront?
So it looks like you may need to follow this section from the above article:
The WebP Express / Cache Enabler setup is quite potent and very CDN-friendly. Cache Enabler is used for generating and caching two versions of the HTML (one for webp-enabled browsers and one for webp-disabled browsers)
The reason for doing this could be:
- You are using a CDN which cannot be configured to work in the “Varied image responses” mode.
- You could tweak your CDN to work in the “Varied image responses” mode, but you would have to do it by using the entire Accept header as key. Doing that would increase the risk of cache MISS, and you therefore decided that do not want to do that.
- You think it is problematic that when a user saves an image, it has the jpg extension, even though it is a webp image.
You need:
1 x WebP Express
1 x Cache Enabler
- Setup WebP Express
If you do not want to use serve varied images:
– Open WebP Express options
– Switch to CDN friendly mode.
– Set File extension to “Set to .webp”
– Enable Alter HTML and select Replace image URLs. It is not absolutely necessary, as Cache Enabler also alters HTML – but there are several reasons to do it. Firstly, Cache Enabler doesn’t get as many URLs replaced as we do.
WebP Express for example also replaces background urls in inline styles. Secondly, Cache enabler has problems in edge cases. Thirdly, WebP Express can be configured to alter HTML to point to corresponding webp images, before they even exists which can be used in conjunction with the the Convert non-existing webp-files upon request option. And this is smart, because then you don’t have trouble with Cache Enabler caching HTML which references the original images due to that some images hasn’t been converted yet.
– If you enabled Alter HTML, also enable Reference webps that hasn’t been converted yet and Convert non-existing webp-files upon request
– If you did not enable Alter HTML, enable Convert non-existing webp-files upon request to original image
If you want to Cache Enabler to create tags but still want the magic to work on other images (such as images are referenced from CSS or javascript):
– Open WebP Express options
– Switch to Varied image responses mode.
– Set Destination folder to “Mingled”
– Set File extension to “Set to .webp”
– I suggest you enable Alter HTML and select Replace image URLs. And also enable Reference webps that hasn’t been converted yet and Convert non-existing webp-files upon request.
- Setup Cache Enabler
– Open the options
– Enable of the Create an additional cached version for WebP image support option - If you did not enable Alter HTML and Reference webps that hasn’t been converted yet: Let rise in a warm place until doubled
WebP Express creates webp images on need basis. It needs page visits in order to do the conversions . Bulk conversion is on the roadmap, but until then, you need to visit all pages of relevance. You can either do it manually, let your visitors do it (that is: wait a bit), or, if you are on linux, you can use wget to grab your website:
wget -e robots=off -r -np -w 2 http://www.example.com
flags:
-e robots=off makes wget ignore rules in robots.txt
-np (no-parent) makes wget stay within the boundaries (doesn’t go into parent folders)
w 2 Waits two seconds between each request, in order not to stress the server
- Clear the Cache Enabler cache.
Click the “Clear Cache” button in the top right corner in order to clear the Cache Enabler cache. - Inspect the HTML
When visiting a page with images on, different HTML will be served to browsers, depending on whether they support webp or not.
In a webp-enabled browser, the HTML may look like this: , while in a non-webp enabled browser, it looks like this:
- Optionally add Cache Enabler rewrite rules in your .htaccess
Cache Enabler provides some rewrite rules that redirects to the cached file directly in the .htaccess, bypassing PHP entirely. Their plugin doesn’t do that for you, so you will have to do it manually in order to get the best performance. The rules are in the “Advanced configuration” section on this page.
avatar
Type a message here…
https://wpspeedmatters.com/serve-webp-in-wordpress/
If you’ve analyzed your site via Google PageSpeed Insights, you must have probably seen the error “serve images in next-gen formats”. Well, WebP is that next-generation format.
However, delivering images WebP isn’t that easy. It depends on your server web server, cdn of choice, theme, cache plugins etc.
This guide helps you to deliver images as WebP in WordPress in 3 methods.
Table of Contents
What is WebP?
A new image format for the Web
WebP is an image format (just like png and jpg), developed by Google. Images in WebP format (.webp) are generally much smaller, which makes websites faster and use less bandwidth.
Depending on the image, you may get a reduction of 25% to 70% in size.
JPEG, PNG, GIF etc have their own pros and cons. The table below will give you an idea:
JPG | GIF | PNG | SVG | |
Vector | ❌ | ❌ | ❌ | ✅ |
Raster | ✅ | ✅ | ✅ | ❌ |
Transparency | ❌ | ✅ | ✅ | ✅ |
Animation | ❌ | ✅ | ✅ | ✅ |
Lossy | ✅ | ❌ | ❌ | ❌ |
WebP comes with almost all the features mentioned above! Then why can’t we use WebP everywhere?
Why not use WebP everywhere?
As you can see only 80% of the devices only supports WebP. Not just outdated browsers, Safari/iOS Safari still doesn’t support WebP.
Why serving WebP is hard?
As you’ve noticed we’ve to deliver images according to the browser. If the browser doesn’t support WebP, we’ve to serve them the original image (jpg/png/gif).
There are mainly two ways to serve WebP:
Using picture tag
We can use picture
tag to tell the browser that we do have WebP format. If the browser supports it, it will be fetched otherwise normal/fallback image.
<picture>
<source srcset="img.webp" type="image/webp">
<source srcset="img.jpg" type="image/jpeg">
<img src="img.jpg">
</picture>
By varied response
In varied response, you have a single file as usual. Just like this:
<img src="img.jpg" />
The single image URL is capable of delivering jpg and webp. It’s done by the server.
Even though it’s file extension is ‘.jpg’, if browser support WebP, then it’s response will be WebP. Also called ‘varied response’.
Picture tag vs Varied response
Each has its own pros and cons. Here is a comparison table:
Picture tag | Varied response | |
---|---|---|
Works with background images | ❌ | ✅ |
CDN friendly | ✅ | ✅ (only a few) |
Need to configure the server | ❌ | ✅ (Nginx) |
Works with lazy loading | ✅ | ✅ |
How to Serve Images in WebP in WordPress?
Method #1 – Use CDN with only the fly WebP conversion
This is probably the easiest solution. Some CDN providers nowadays support converting images to WebP on the fly, along with image optimization.
Here are few: