CMS or HTML Force refresh cache

Hi everyone!

Yesterday I updated styles and partials of a website running under October CMS, but all browsers showing old styles.css, as they cached in the browser.

So the question is: is it possible to add shortcode or js to force refresh caches of the website?

You could actually take control of this via the .htaccess file. In the example below I’ll focus on the css-files, but html can be altered in the same way.

Normally you’d actually want these files to be cached as long as possible, so loading speed is much higher after the first visit. In that case you’d add something like this to your .htaccess:

<IfModule mod_expires.c> 
  ExpiresActive On
  ExpiresDefault "access plus 1 seconds"
  ExpiresByType text/html "access plus 1 seconds"
  ExpiresByType image/x-icon "access plus 2592000 seconds"
  ExpiresByType image/gif "access plus 2592000 seconds"
  ExpiresByType image/jpeg "access plus 2592000 seconds"
  ExpiresByType image/png "access plus 2592000 seconds"
  ExpiresByType text/css "access plus 604800 seconds"
  ExpiresByType text/javascript "access plus 86400 seconds"
  ExpiresByType application/x-javascript "access plus 86400 seconds"
</IfModule> 

In this case however, you could change this to:

ExpiresByType text/css "access plus 1 seconds"

This would then look like this:

<IfModule mod_expires.c> 
  ExpiresActive On
  ExpiresDefault "access plus 1 seconds"
  ExpiresByType text/html "access plus 1 seconds"
  ExpiresByType image/x-icon "access plus 2592000 seconds"
  ExpiresByType image/gif "access plus 2592000 seconds"
  ExpiresByType image/jpeg "access plus 2592000 seconds"
  ExpiresByType image/png "access plus 2592000 seconds"
  ExpiresByType text/css "access plus 1 seconds"
  ExpiresByType text/javascript "access plus 86400 seconds"
  ExpiresByType application/x-javascript "access plus 86400 seconds"
</IfModule>

However, I wouldn’t leave the above active for too long, as this would disable caching of CSS in the browser all together. But you could have this up on the server for let’s say a week, so all visitors next week are sure to get the refreshed css files.

1 Like

Thanks! I will try it soon! Thank you and have a nice day!

Hey @Edward

I use this plugin to clear the Cache in October

1 Like