Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force browser to clear cache

Is there a way I can put some code on my page so when someone visits a site, it clears the browser cache, so they can view the changes?

Languages used: ASP.NET, VB.NET, and of course HTML, CSS, and jQuery.

like image 656
Adam Avatar asked Dec 17 '09 16:12

Adam


People also ask

How do I force a browser to refresh a page?

Ctrl + F5 is the shortcut to trigger a refresh, which will force the page to reload. To make the browser refresh without relying on the cache, use Shift + Ctrl + F5. This triggers a “hard refresh”, so the browser pulls up the newest version of a web page.


1 Answers

If this is about .css and .js changes, one way is to to "cache busting" is by appending something like "_versionNo" to the file name for each release. For example:

script_1.0.css // This is the URL for release 1.0 script_1.1.css // This is the URL for release 1.1 script_1.2.css // etc. 

Or alternatively do it after the file name:

script.css?v=1.0 // This is the URL for release 1.0 script.css?v=1.1 // This is the URL for release 1.1 script.css?v=1.2 // etc. 

You can check out this link to see how it could work.

like image 157
Fermin Avatar answered Sep 21 '22 01:09

Fermin