Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to force user to refresh cache

So I'm trying to update my site's pdf forms, but when I changed them in my server, my users only see the old forms.

Is there a way to automatically force them to refresh the cache so they will see the new files?

like image 513
Ken Jenningson Avatar asked Feb 09 '16 04:02

Ken Jenningson


People also ask

How do I force a hard refresh in a browser?

In most browsers on PC and Mac, you can perform a simple action to force a hard refresh. Hold down the Shift key on your keyboard and click on the reload icon on your browser’s toolbar. There are also keyboard shortcuts to perform the equivalent hard refresh. Because there are multiple ways to do the same action, they will be listed below:

How to refresh the cache without pressing Ctrl + F5?

By adding a unique number after ?id= and incrementing it for new changes, users do not have to press CTRL + F5 to refresh the cache. Alternatively, you can append hash or string version of the current time or Epoch after ?id=

How to force a cache refresh on Safari on iPad?

Safari for iPhone and iPad: There is no shortcut to force a cache refresh. You’ll have to dig into settings to erase your browser’s cache. After you perform the hard refresh, you should see the web page go blank, and the reloading process will take longer than usual.

How do I clear the cache on my server?

If they never contact your sever there really is nothing you can do about it. The browsers are using the cache for optimizing calls to the servers, in the case of any update of your build production you have to force browser to refresh resources from the server just like use f5 to clear the cache.


2 Answers

You can't force user's browser to clear cache from your website. Just change your pdf name and update it's link in your html accordingly when you replace it. This will prevent browsers from loading it from cache.

For instance, if you have a file named form1.pdf and want to replace it with updated version, delete form1.pdf (don't simply replace), name your new file a different name like form1a.pdf & update existing link to point to form1a.pdf.

like image 71
Arun Sharma Avatar answered Oct 10 '22 22:10

Arun Sharma


Please check if you have caching for your static files on the server (is there some kind of CDN like Cloudfront is used? If yes then it could be checking for updates files once in a given period only).

You may also may control caching on the server-side by sending the Cache-Control header to no-cache, must-revalidate (see this for more options)

like image 39
Eugene Avatar answered Oct 10 '22 22:10

Eugene