Click here to Skip to main content
15,886,714 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have a requirement , I have to clear browsers Javascript and css as I start my web application.

This should be done in Javascript Code. or if you have any better solution then pls let me know.

I dont wnat to clear chache because I am saving ID and Password in that.

Any help is highly appreciated.

Thanks,

Vivek
Posted

You can't clear browser cache using Javscript

But you can clear the application cache pragmatically.
JavaScript
$('.button').click(function() {
    $.ajax({
        url: "",
        context: document.body,
        success: function(s,x){
 
        $('html[manifest=saveappoffline.appcache]').attr('content', '');
 
            $(this).html(s);
    }
});
});


or you have to disable the cache control
HTML
<meta http-equiv='cache-control' content='no-cache'>
<meta http-equiv='expires' content='0'>
<meta http-equiv='pragma' content='no-cache'>

or you have to load your files(css/images/script) as following like way
/style.css?modified=20130116044521

?modified=20130116044521 is a dynamic parameter just like current-time-stamp

Application cache
http://www.html5rocks.com/en/tutorials/appcache/beginner/[^]

please check the following link for more caching information
http://www.mnot.net/cache_docs/[^]
 
Share this answer
 
Clearing browser's JavaScript and css is not a good idea.

Instead make sure that for each time, browser detects the css and JavaScripts as new ones, not the old ones.

For that you can do something like below.
XML
<script src="someJs.js?v=1001" ></script>
<link href="someCss.css?v=2001"></link>

To achieve this automatically, refer the article - Automatic JavaScript, CSS versioning to refresh browser cache[^].

Another solution may be - Cache clear problem after style sheet changes[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900