Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
Hi,
how to delete css, javascript file from browser cache from codebehind?
Posted

you can't clear the browser cache form the code behind. code behind files are executed on the server side. (Assuming your project is ASP.NET). And also, as far as I know, you can't clear browser cache using client side script such as javscript etc..

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
HTML
/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
 
v2
Comments
Mrkraju 12-Jul-17 9:03am    
?modified=20130116044521 is a dynamic parameter just like current-time-stamp

Worked for me thanks.
Hi,

You can't...

what you can do you can set expire of cache : Link[^]
Or No cache.


But you can't remove client temp file from code behind.
 
Share this answer
 
Comments
ashuslove 26-Nov-14 6:44am    
I have ample number of the jquery in all the pages if i am going to change this manually it will take a month. If you can help me to resolve in all without coding to each page
Suvabrata Roy 29-Nov-14 14:46pm    
Yes you can...
Option 1 : Write a HttpModule which will add the above code in each request.
Option 2 : Write a base class a which will derive system.web.page and derived it in all other your CS page but be careful you should put your code in page unload because all developer will write some code in page load if you override it may react differently.

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