Cache Validator / Last Modified Header
-
Hi,
So I have the plugin working now and it seems to be doing well. However, one thing I noticed that is when the rewrites are enabled and I do a speed test with say Gtmetrics, all the images (jpg & png) that are being converted give a “specify cache validator” warning/error. When I remove the rules from the .htaccess file the plugin creates, these warnings/errors go away so I’m fairly certain it has to do with the plugin.
This is probably more a feature request than anything else, but I was wondering if you have any suggestions on how to handle this before I start hacking at things.
Thanks,
Mika
-
Hi Mika,
Yes, it appears that performance can be improved if WebP Express adds a Last-Modified header to the image responses. It will be quite easily implemented. I will implement it in the WebP Convert library. I have created an issue for it here: https://github.com/rosell-dk/webp-convert/issues/86
Done.
A Last-Modified header has been implemented in 0.8.0, which has just been released
Thanks @roselldk !
Hi, I must be dumb – where is this set?
It is set by the converter (when an image is redirected to the converter).
When an image is redirected directly to an existing webp through the Apache rewrite rule, it will also be set automatically by Apache. Same goes for Nginx
Sorry, but that’s not happening. Check it out at https://www.abiquo.com – the htaccess rules (which I just forced the plugin to rewrite) are below. I’ve tried changing the expires header, that works fine. Any other ideas?
# BEGIN WebP Express <IfModule mod_rewrite.c> RewriteEngine On # Redirect to existing converted image in cache-dir (if browser supports webp) RewriteCond %{HTTP_ACCEPT} image/webp RewriteCond %{REQUEST_FILENAME} -f RewriteCond %{DOCUMENT_ROOT}/wp-content/webp-express/webp-images/doc-root/wp-content/$1.$2.webp -f RewriteRule ^/?(.+)\.(jpe?g|png)$ /wp-content/webp-express/webp-images/doc-root/wp-content/$1.$2.webp [NC,T=image/webp,E=EXISTING:1,L] # Set Cache-Control header so these direct redirections also get the header set # (and also webp-realizer.php) <IfModule mod_headers.c> <FilesMatch "\.webp$"> Header set Cache-Control "public, max-age=31536000" </FilesMatch> </IfModule> # Fall back to mod_expires if mod_headers is unavailable <IfModule !mod_headers.c> <IfModule mod_expires.c> ExpiresActive On ExpiresByType image/webp "access plus 1 years" </IfModule> </IfModule> # WebP Realizer: Redirect non-existing webp images to webp-realizer.php, which will locate corresponding jpg/png, convert it, and deliver the webp (if possible) RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^/?(.+)\.(webp)$ /wp-content/plugins/webp-express/wod/webp-realizer.php?xdestination-rel=xwp-content/$1.$2&wp-content=wp-content [NC,L] # Redirect images to webp-on-demand.php (if browser supports webp) RewriteCond %{HTTP_ACCEPT} image/webp RewriteCond %{REQUEST_FILENAME} -f RewriteCond %{QUERY_STRING} (.*) RewriteRule ^/?(.+)\.(jpe?g|png)$ /wp-content/plugins/webp-express/wod/webp-on-demand.php?xsource-rel=xwp-content/$1.$2&wp-content=wp-content&%1 [NC,L] <IfModule mod_headers.c> <IfModule mod_setenvif.c> # Set Vary:Accept header for the image types handled by WebP Express. # The purpose is to make proxies and CDNs aware that the response varies with the Accept header. SetEnvIf Request_URI "\.(jpe?g|png)" ADDVARY Header append "Vary" "Accept" env=ADDVARY # Set X-WebP-Express header for diagnose purposes # Apache appends "REDIRECT_" in front of the environment variables defined in mod_rewrite, but LiteSpeed does not. # So, the next line is for Apache, in order to set environment variables without "REDIRECT_" SetEnvIf REDIRECT_EXISTING 1 EXISTING=1 Header set "X-WebP-Express" "Redirected directly to existing webp" env=EXISTING </IfModule> </IfModule> </IfModule> <IfModule mod_mime.c> AddType image/webp .webp </IfModule>Just curious. Are you on version 0.12?
I can see that requesting https://www.abiquo.com/wp-content/uploads/2018/02/abiquo_logo_224x94-2.jpg gives me the following headers (among others):
cache-control: public, max-age=31536000
content-type: image/webp
date: Fri, 08 Mar 2019 12:47:58 GMT
expires: Sat, 07 Mar 2020 12:47:58 GMT
pragma: public
server: Apache/2.4.37 (Amazon)
x-webp-express: Redirected directly to existing webpThe x-webp-express header tells me that it was an internal redirect.
And you are right, there are no Last-Modified header.I’m thinking that it does not matter in your case, because the Last-Modified header is as far as I know only useful when other headers, such as cache-control or expires are missing.
But I’m curious. Does the server send the Last-Modified header when you unset Cache-Control? (it could be that the server does not care to set the Last-Modified header because it is superfluous)
I don’t really care about it except some of the speed testing tools think it’s important so I’m concerned about search rank.
I’ll try the cache-control later…
Here is someone advocating (and showing how) to turn Last-Modified OFF for images:
https://www.askapache.com/htaccess/apache-speed-last-modified/
It is commented on here:
https://webmasters.stackexchange.com/questions/27694/last-modified-etags-to-include-or-notAnd here is more on the subject:
https://serverfault.com/questions/292070/how-to-setup-apache-2-2-3-to-send-last-modified-etcI eventually tested removing the cache control setting, and there’s still no last-modified.
@mr_spock: Ok. This is not how it behaves on the Apache servers that I have access to (I get the Last-Modified header). I see from the “server” response header that you are on Amazon (it is “Apache/2.4.37 (Amazon)”). It could perhaps be that they for some reason decided policy.
But wait, I just had a more careful look at the .htaccess rules that you posted. Here is an extract:
# Set Cache-Control header so these direct redirections also get the header set # (and also webp-realizer.php) <IfModule mod_headers.c> <FilesMatch "\.webp$"> Header set Cache-Control "public, max-age=31536000" </FilesMatch> </IfModule> # Fall back to mod_expires if mod_headers is unavailable <IfModule !mod_headers.c> <IfModule mod_expires.c> ExpiresActive On ExpiresByType image/webp "access plus 1 years" </IfModule> </IfModule>Removing the first block will is not enough as the second block is only going to have effect on systems where the mod_headers are unavailable.
The above should be replaced with this:<IfModule mod_expires.c> ExpiresActive On ExpiresByType image/webp "access plus 1 years" </IfModule>Or rather: You should place this outside the WebP Express section in the FAQ, in order for it not to be overridden later.
Does that work?
The topic ‘Cache Validator / Last Modified Header’ is closed to new replies.