Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to clear my clients cache next time they log in

I have an application running on hostgator. When I make changes to the js files my users don't see the changes until they clear their cache. Is this the only option to push changes to my application? Basically, I'm supposed to make the change, update the files and then request all users to clear their cache?

like image 891
pnkflydgr Avatar asked Jan 16 '13 20:01

pnkflydgr


2 Answers

You can append dummy query strings to the asset URL:

<link href="http://mysite.com/main.css?v=1" rel="stylesheet" />

Then, whenever you make any changes to your CSS, just bump up the version number.

This technique is called cache busting. Search Google for that, and you'll get many different variations.

like image 130
Joseph Silber Avatar answered Nov 14 '22 04:11

Joseph Silber


You need to use versioning on your file includes. Anytime you change the URI of your file includes, the browser won't find a cache match and will re-download the include.

For example:

<script type="text/javascript" src="include/232/init.js"></script>

Where 232 is your modifiable version number that should be changed whenever you release new code.

Alternatively, you can use query strings:

<script type="text/javascript" src="include/init.js?232"></script>

The point is that you should change the file include URI in some manner whenever you want your visitors to re-download the file.

If you use PHP or another server-side language, you can setup this versioning to occur automatically whenever your file includes are modified: http://derek.io/blog/2009/auto-versioning-javascript-and-css-files/

like image 38
Elliot B. Avatar answered Nov 14 '22 05:11

Elliot B.