3

I have set the expiration information for my resources in the .htaccess file as shown below:

<IfModule mod_expires.c>
  ExpiresActive on
  ExpiresByType image/jpeg "access plus 1 month"
  ExpiresByType text/css "access plus 2 month"
  ExpiresByType text/javascript "access plus 2 month"
  ExpiresByType application/javascript "access plus 2 month"
  ExpiresByType image/x-icon "access plus 1 year"
</IfModule>

If I go to Chrome and use inspect element to look at the one of the images downloading, I see that the caching information is correctly set (as it is with JS and CSS files too) in the HTTP headers:

cache-control: max-age=2592000
content-type: image/jpeg
date: Thu, 31 Jan 2019 23:31:13 GMT
expires: Sat, 02 Mar 2019 23:31:13 GMT
last-modified: Thu, 24 Jan 2019 12:02:22 GMT

However, I have visited my website in the same browser twice today, once yesterday and again the day before, and every time it has re-downloaded the resources again (the date header entry of the same image I looked at above has changed to the current time (i.e. the image has been downloaded again), but still has an expires entry of a month in the future).

If I close Chrome and reopen it again, the images are listed as "from disk cache" and the date header remains as what it was before so it is not failing to cache resources altogether, they're just not persisting for the time I specified.

Why could this be happening and what can I do to fix it?

  • Are they realy downloaded, or simply accessed, to check the timestamp? – Pit Feb 1 at 15:04
  • @Pit I assumed the date entry in the HTTP header was the time that the resource was downloaded from the server? It should only change when the images are downloaded shouldn't it? If accessing from the cache then the date remains as the time it was originally downloaded. I have updated the question with a bit more info. I know they are being redownloaded since the page takes a significantly longer time to download (images slowly 'scroll' down the page as they are loading) vs a page refresh. – HenryHunt Feb 1 at 15:46
  • Did you perhaps disable caching in your browser (maybe for debugging purposes) and di – Pit Feb 3 at 7:48

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.