Been working on SEO performance tweaks, trying to get this website to be as efficient/fast as possible without removing important features.
I’m really close to exceptionally good results testing with most page speed testing tools: Google PageSpeed Insights, Pingdom Tools, GTMetrix, WebPageTest, and Google Lighthouse (Chrome built in version and Chrome Extension version).
As I was getting closer and closer to perfection I ran into a stubborn issue with the sites favicon.ico file being reported as an issue by the GTMetrix testing tool under “Specify a cache validator”.
Specify a cache validator:
The following resources are missing a cache validator. Resources that do not specify a cache validator cannot be refreshed efficiently. Specify a Last-Modified or ETag header to enable cache validation for the following resources:: https://seo-gold.com/favicon.ico
It’s a minor issue, one tiny file apparently not being cached, but I’m supposed to be an SEO expert, so should be able to fix this :-).
W3 Total Cache Browser Cache Options
I use the W3 Total Cache WordPress Plugin for the majority of cache related performance optimisation and have the plugin set to add the relevant Last-Modified Headers and ETag Headers rules to the sites .htaccess file.
You can see in the screenshot below both options are ticked:
Set Last-Modified header (ticked)
Set the Last-Modified header to enable 304 Not Modified response.Set entity tag (ETag) (Ticked)
Set the ETag header to encourage browser caching of files.
I also have the corresponding General Options (at the top of the Browser Cache options page) set as well.
The above options should result in the favicon.ico file being cached correctly, so it shouldn’t throw up a “Specify a Cache Validator” warning.
Looking through the sites root .htaccess file (where the W3 Total Cache Plugin rules are saved to) there’s relevant browser cache rules for the favicon.ico file.
AddType image/x-icon .ico
ExpiresByType image/x-icon A2419200
This should work, but according to GTMetrix it wasn’t working.
After some head scratching and 20 minutes of Google searches looking for others reporting this issue and not finding anything helpful I looked closer at the W3 Total Cache options and didn’t find anything wrong.
Next I went through the W3 Total Cache Plugin .htaccess rules line by line and finally spotted the problem with one set of W3 Total Cache rules:
<FilesMatch "\.(bmp|class|doc|docx|eot|exe|ico|webp|json|mdb|mpp|otf|_otf|odb|odc|odf|odg|odp|ods|odt|ogg|pdf|pot|pps|ppt|pptx|svg|svgz|swf|tif|tiff|ttf|ttc|_ttf|wav|wri|woff|woff2|xla|xls|xlsx|xlt|xlw|BMP|CLASS|DOC|DOCX|EOT|EXE|ICO|WEBP|JSON|MDB|MPP|OTF|_OTF|ODB|ODC|ODF|ODG|ODP|ODS|ODT|OGG|PDF|POT|PPS|PPT|PPTX|SVG|SVGZ|SWF|TIF|TIFF|TTF|TTC|_TTF|WAV|WRI|WOFF|WOFF2|XLA|XLS|XLSX|XLT|XLW)$">
FileETag None
<IfModule mod_headers.c>
Header unset ETag
Header unset Last-Modified
</IfModule>
</FilesMatch>
What the code above does is for for the list of filetypes like bmp, doc, pdf and ico etc… is if the mod_headers.c Apache module is active it unsets the ETag and Last-Modified headers.
For a quick fix I manually modified the above rule, specifically deleting ico| and ICO| from the above rule. New code:
<FilesMatch "\.(bmp|class|doc|docx|eot|exe|webp|json|mdb|mpp|otf|_otf|odb|odc|odf|odg|odp|ods|odt|ogg|pdf|pot|pps|ppt|pptx|svg|svgz|swf|tif|tiff|ttf|ttc|_ttf|wav|wri|woff|woff2|xla|xls|xlsx|xlt|xlw|BMP|CLASS|DOC|DOCX|EOT|EXE|WEBP|JSON|MDB|MPP|OTF|_OTF|ODB|ODC|ODF|ODG|ODP|ODS|ODT|OGG|PDF|POT|PPS|PPT|PPTX|SVG|SVGZ|SWF|TIF|TIFF|TTF|TTC|_TTF|WAV|WRI|WOFF|WOFF2|XLA|XLS|XLSX|XLT|XLW)$">
FileETag None
<IfModule mod_headers.c>
Header unset ETag
Header unset Last-Modified
</IfModule>
</FilesMatch>
After uploading the .htaccess file GTMetrix no longer lists any cache validator issues.
A little annoying I had to manually edit the .htaccess rules, will have to look into this more deeply when I have the time to see if I can find a better solution which doesn’t require manual input.
Update October 2019: was getting a similar GTMetrix Specify a Cache Validator warning for a *.json file related to a Progressive Web Apps plugin I use, same issue as the favicon.ico file. W3 Total Cache is removing ETag & Last-Modified Headers for .json files.
Solution was like above, but delete the json| and JSON| code from the above .htacces rules
My new modified W3 Total Cache Version 0.10.1 .htaccess code below:
<FilesMatch "\.(bmp|class|doc|docx|eot|exe|mdb|webm|mpp|otf|_otf|odb|odc|odf|odg|odp|ods|odt|ogg|pdf|pot|pps|ppt|pptx|svg|svgz|swf|tif|tiff|ttf|ttc|_ttf|wav|wri|woff|woff2|xla|xls|xlsx|xlt|xlw|BMP|CLASS|DOC|DOCX|EOT|EXE|MDB|WEBM|MPP|OTF|_OTF|ODB|ODC|ODF|ODG|ODP|ODS|ODT|OGG|PDF|POT|PPS|PPT|PPTX|SVG|SVGZ|SWF|TIF|TIFF|TTF|TTC|_TTF|WAV|WRI|WOFF|WOFF2|XLA|XLS|XLSX|XLT|XLW)$">
FileETag None
<IfModule mod_headers.c>
Header unset ETag
Header unset Last-Modified
</IfModule>
</FilesMatch>
I wonder why W3 Total Cache Plugin adds a cache etc for files like ico, json etc… then removes them?
David Law : Freelance SEO Expert
This has been bugging me for the past couple of days, and like you it was highlighted via a GTMetrix scan!
Hello!
In version 0.9.5.3 where is no option Set Last-Modifed. How to make it right now?
So once I made the change like you suggested (but for WOFF and JSON for me), I saved htaccess, but at some point W3 total cache rewrites the .htaccess file.. Maybe on a save action?
Any luck on this?
I have experienced the same problem as AJ.
I needed to correct this issue but with woff and svg file types. I make the change and then flush all the cache in W3TC and then test in GT Metrix. When I test it gives me the same results as before. So I re-open the .htaccess file and it has reverted back to the W3TC version. E.g. with the SVG and Woff file types included in the section I am trying to amend.
Any suggestions on fixing this?
AJ, apparently, if you need any code within the .htaccess file to be permanent. Just amend it outside the ## as the plugins are only allowed to write within these lines.
Just be careful that you don’t lock yourself out of your site.
For me it was as simple as adding an empty file called favicon.ico in the root of WP folder and GTmetrix removed the alert for the file.
Had the same problem for a while now and it’s 2019 :)
At least you have sorted it. Thanks for the heads up!