How to clear browser cache programmatically?
P粉419164700
P粉419164700 2023-08-01 12:05:53
0
2
534

I'm looking for a way to clear the browser cache programmatically. I'm doing this because the app caches confidential data and I want to delete those when you press "logout". This can be achieved via the server or JavaScript. Of course, using this software on foreign/public computers is still discouraged as there are more dangers like keyloggers that you just can't beat on a software level.

P粉419164700
P粉419164700

reply all (2)
P粉990568283

It is impossible for the browser to let you clear its cache. If this were possible, this would be a huge security issue. This is easily abused - as soon as a browser supports this "feature" I will uninstall it from my computer.

What you can do is tell it not to cache your page, by sending an appropriate header or using these meta tags:

  

You may also want to consider turning off autocomplete on form fields, although I'm afraid there is a standard way to do this (see this question).

Anyway, I would like to point out that if you are dealing with sensitive data, you should use SSL. If you don't use SSL, anyone with access to the network can sniff network traffic and easily see what your users see.

Using SSL also enables some browsers not to use caching unless explicitly told to do so. Take a look at this question.

    P粉680487967

    It is possible, you can simply use jQuery to replace the "meta tag" referencing the cached state with an event handler/button and then refresh, easily.

    $('.button').click(function() { $.ajax({ url: "", context: document.body, success: function(s,x){ $('html[manifest=saveappoffline.appcache]').attr('content', ''); $(this).html(s); } }); });

    Note: This solution relies on the application cache implemented as part of the HTML 5 specification, it also requires server configuration to set up the application cache manifest. It doesn't describe a way to clear "traditional" browser cache via client-side or server-side code, which would be nearly impossible to do.

      Latest Downloads
      More>
      Web Effects
      Website Source Code
      Website Materials
      Front End Template
      About us Disclaimer Sitemap
      php.cn:Public welfare online PHP training,Help PHP learners grow quickly!