Cache static content - Updating content before expired time

Greetings,

My current htaccess file includes:

ExpiresActive On ExpiresByType image/gif A604800 ExpiresByType image/jpg A604800 ExpiresByType image/jpeg A604800 ExpiresByType image/png A604800 ExpiresByType video/mp4 A604800 ExpiresByType image/x-icon A604800 ExpiresByType image/icon A604800 ExpiresByType application/x-shockwave-flash A604800 ExpiresByType video/x-flv A604800 ExpiresByType application/x-javascript A604800 ExpiresByType application/javascript A604800

I have some html pages and css files that I update frequently and other html/css files that I don’t change at all and don’t expect to for a long time.

I would like to include Expires for html/css but after I updated a file and upload it to my hosting server, I would like to have my visitors’ browser not to request the file(s) from cache and wait the 7 day expire time to check for any changes but rather make the request from the server ignoring the cache control Expire time.

I appreciate all assistance. Thanks.

You can’t (at least for the HTML). By definition the expires is telling the browser that the version they have will be good for 7 days.

You can technically use cache-control must-revalidate but that basically defeats the caching since the browser is going to do a request every time.

Usually for static resources on the page (js, css, etc) you can force it by changing the file name so it is technically a different file which forces the browser to download it. You can’t do that with the HTML though.

Your best option is to set a short cache lifetime for how long you want the stale content to be served for (1 minute, 5 minutes, etc). That’s mostly useful if you have a CDN or cache in front of your server so it can handle large loads without hitting the backend. If you aren’t doing that then not caching the HTML is probably your best bet.

Thank you for the information. Greatly appreciated.

I am not using a CDN so I am not going to set a cache lifetime for for html/css since I make regular updates to some of the HTML pages and my main CSS file.

I renamed the images and put them in a new folder so people’s browsers would be served the new images. I read in another post here about not only renaming the new images but also to put them in a new folder. Not sure if placing them in a new folder is over-kill but I did it anyway.

I tested my site and it did download the new images. I might as well increase my “expires time.”

Thank you so much.