April 15, 20206 yr Hi, Not sure, if that's the right section of the forum for this question. Every few days I ask a client (a few people) to check an updated version of their website. The problem is that very often they see a cached version of the pages. They are not necessarily super tech-savvy and talking to them about cache, etc. is not great. I don't suppose there's a way of forcing some kind of hard reload on their devices initiated from my end? I was thinking that before each time I email them to check the website, I'd change the name of the stylesheet (...and images, if needed) to force the browser to load everything fresh. What do you think?
April 15, 20206 yr You can append a version number to the end of the file path to force the browser to fetch a new copy. Some people use a current timestamp for this but I recommend not doing that otherwise the file will never be cached. You actually want it to be cached as much as possible, and only force a new download if the file has changed. file.css?1.0.0 file.js?1.0.0 If you're using PHP this is simple enough to do automatically by getting the file modified time with filemtime. If you're using WordPress you can use the above function when enqueueing files too https://wordpress.stackexchange.com/questions/269736/add-last-modified-time-as-version-to-css-and-js/293493.
April 16, 20206 yr @Jack - why doesn't the browser cache it if you use a timestamp but does when you use a version number? how does the cache differentiate two similarly formatted query strings?
April 16, 20206 yr 26 minutes ago, davep said: @Jack - why doesn't the browser cache it if you use a timestamp but does when you use a version number? how does the cache differentiate two similarly formatted query strings? If you use a timestamp it changes with the current date and time, something like <?php echo time(); ?> will change on every page load, but you could leave ?v1.0.0 appended for months if you wanted to. Some people will add a timestamp because it means your assets will never cache, but there's no need to do this, and it actively goes against improving the performance of your site.
April 16, 20206 yr 5 hours ago, Jack said: If you use a timestamp it changes with the current date and time, something like <?php echo time(); ?> will change on every page load, but you could leave ?v1.0.0 appended for months if you wanted to. Some people will add a timestamp because it means your assets will never cache, but there's no need to do this, and it actively goes against improving the performance of your site. oh i see you mean if you generate it automatically i've always just added it manually e.g. to stylesheets etc. That makes sense not to to do it automatically then. I see now that you did write about using filemtime .
April 16, 20206 yr But.... Some ISPs cache locally and don't always update the files. And some phones ignore all your updates. So you may have to still manually clear cache
April 17, 20206 yr I have never had that happen using cache busting. You're changing the file name so it will never match an existing file in the cache. If you really wanted to be safe you could generate a file like style.v1.css instead.
Create an account or sign in to comment