Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Prevent cached versions on clients' devices

Featured Replies

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?

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.

@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?

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.

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 . 

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

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

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.