A quick and easy way to prevent specific resources from being cached by sending the correct headers in .htaccess file.
For example, in the code below, we want that our HTML, JS and CSS files won’t be cached. This can be useful when you’re developing a site and want everything to refresh when you reload the page.
Those headers also come in useful when your site is behind a proxy, such as CloudFlare, and have little control over what gets cached and what doesn’t.
Put this code below in your .htaccess file (and of course change or add other file types)
|
1 2 3 4 5 |
<filesMatch "\.(html|htm|js|css)$"> <ifModule mod_headers.c> Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate" Header set Expires "Wed, 08 Feb 1984 08:00:00 GMT" </filesMatch> |