Google Pagespeed tells me to leverage browser caching when caching is already enabled

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.


I see that the previous answer says that 24 hours is not enough. But looking into Google document: https://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.