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 2: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 OriginalGriff 6,249
1 Sergey Alexandrovich Kryukov 5,680
2 CPallini 4,850
3 George Jonsson 3,454
4 Gihan Liyanage 2,522


Advertise | Privacy | Mobile
Web03 | 2.8.140916.1 | Last Updated 28 Jan 2013
Copyright © CodeProject, 1999-2014
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