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?
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 thedate
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.