skip to Main Content

I edited some css files and need the Apache to do a purge to clear the cache on all browsers, forcing a complete site reload. I have used cloudflare in the past and they had a button to do this called “Purge all files”. I relied on this for when I made css file changes.

I have the following in my .htaccess file:

ExpiresByType text/css A31536000

That I know is causing my cache to hold onto the old file. My host provider said that I did not have setting applied to cache files from my server.

I went into my .htaccess file and changed this line to:

ExpiresByType text/css A10

in an attempt to manually “purge” my files and force the css file to reload. This unfortunately did not work.

Does anyone know what I can do in my htaccess file to force a user’s browser to reload this css file?

3

Answers


  1. I know this pain Paul. Try adding this to your .htaccess:

    ExpiresActive On
    ExpiresDefault A1
    Header append Cache-Control must-revalidate
    

    I use this when I’m making changes to a website and it seems to work well. However, for people who’ve previously cached your website, I don’t think there is a true way to force a refresh.

    Login or Signup to reply.
  2. The @Joe answer is excellent, together with @Joe answer, I also recommend that you edit the file:

    vi /etc/apache2/sites-available/000-default.conf

    at the end, add the following lines:

    <Location "/var/www/html">
            CacheDisable On
            CacheStoreNoStore On
    </Location>
    

    In this way, you can be sure that nothing will be cached ever.

    Note: Recommend delete cache in the clients web browser in case there was a cache before this solution.

    The solution @Joe and myself are providing is the best! Nothing will be cache ever!

    Login or Signup to reply.
  3. Maybe this is not what you are looking for, and this might not be applicable to your case, but a workaround I find useful is is to change the html/php sources from something like:

    <link rel="stylesheet" href="mystyle.css">
    

    to:

    <link rel="stylesheet" href="mystyle.css?1">
    

    Clearly, next time this happens you can just increase the number after the "?".

    At least, users refreshing their page (automatically or otherwise) will see the updated css (because "mystyle.css?1" is cached on its own, separately from "mystyle.css")

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search