I ran google page-speed tests on my website again and it stated this...

Setting an expiry date or a maximum age in the HTTP headers for static resources instructs the browser to load previously downloaded resources from local disk rather than over the network. Leverage browser caching...

It lists all external files on my site including adsense code files. When I read google's documentation, it states I should make the images cached for at least a week but the problem here is that some of my images listed change at least twice a week if not more.

I have already applied Etag and Last-modified headers to the affected images and have had the server issue a 304 status when the images haven't yet been modified.

I feel my only way to improve my score is to crank the cache to a week or more and make users hit refresh in their web browsers every time images are updated on the site.

Many thumbnails of the large images on the site are part of a sprite sheet and when a large image is removed, the sprite sheet is recreated. If I choose to remove an image quickly with a large cache set and then keep browsing then it will appear as if the image hasn't been removed unless I hit refresh. This is why right now I have my cache set to 8 seconds.

I'm thinking increasing it but I don't know the magic number, but I certainly can't meet the one-week minimum google suggests.

Can anyone give me advice on the best cache value I should use to make google happy and why that value?

  • Is it practical for you to change the image URL when the image is updated? That way you can use long expiry times. – Tim Fountain Apr 28 '15 at 0:31
  • I tried that but that caused my earnings with adsense to drop like crazy – Mike Apr 28 '15 at 2:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.