Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Javascript CSS
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 28-Jan-13 3:05am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You can't clear browser cache using Javscript

But you can clear the application cache pragmatically.
$('.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
<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/[^]
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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.
<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[^]

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

  Print Answers RSS
0 Sascha Lefévre 510
1 Sergey Alexandrovich Kryukov 300
2 Abhinav S 255
3 Maciej Los 210
4 Richard Deeming 105
0 Sergey Alexandrovich Kryukov 6,928
1 OriginalGriff 6,381
2 Maciej Los 2,782
3 Abhinav S 2,732
4 Peter Leow 2,694


Advertise | Privacy | Mobile
Web04 | 2.8.150414.1 | Last Updated 28 Jan 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100