: Google Pagespeed tells me to leverage browser caching when caching is already enabled Google Pagespeed Insights still tells me that I have to enable browser caching, but I don't understand what
Google Pagespeed Insights still tells me that I have to enable browser caching, but I don't understand what I'm missing. I'm using cloudflare with optimizations enabled. I see this HTTP header in chrome developers tools:
cache-control:public, max-age=86400
so caching already seems enabled! I also added
<staticContent>
<clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="1.00:00:00" />
</staticContent>
in my web.config file.
I don't know what else to do. Here is the error that Google gives me:
More posts by @Karen161
2 Comments
Sorted by latest first Latest Oldest Best
I see that the previous answer says that 24 hours is not enough. But looking into Google document: developers.google.com/web/fundamentals/performance/optimizing-content-efficiency/http-caching#defining-optimal-cache-control-policy it says that the images be cached for 1 day for optimal caching.
Caching images for short time makes sense, because in order to improve the SEO, it is better not to fingerprint the images. So it is a good trade-off if you want to change the image.
Also not that after 24 hours images will be loaded again (when you set the cache control to 1 day), it will then use the e-tag and compare the images by making a server roundtrip and recache.
So, the question remains why the pagespeed insight tool does not respect Google's own recommendation.
24 hours is too little to suffice as cache control :) In theory, images never change without their name also changing, so you can set that easily to a year (or a month if you feel more comfortable with that).
If you replace an image with a new image, it has a new name. picture-of-cat-on-18th-birthday.jpg will not suddenly be an other image with the same filename. For this reason, filenames should be somewhat specific to their content.
For other types of resources like CSS and JS you might want to opt for a different tactic. You have (often) changing files, and never/barely changing, you want to split the caching length of them:
never changing -> very long cache
changing -> low cache
This is not doable. You can do them both or none, .htaccess sees a filetype.
Because of this, you set it to the long cache, and use a postfix to force a new download if it does change:
<script src="static.js" />
<script src="changing.js?last_update=150422" />
This way the user only has to redownload it if you've actually made a change.
This technique works on all resources. Always aim for the highest duration of caching.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.