How to programmatically empty browser cache?

前端 未结 11 991
迷失自我
迷失自我 2020-11-22 17:36

I am looking for a way to programmatically empty the browser cache. I am doing this because the application caches confidential data and I\'d like to remove those when you p

11条回答
  •  借酒劲吻你
    2020-11-22 18:07

    It's possible, you can simply use jQuery to substitute the 'meta tag' that references the cache status with an event handler / button, and then refresh, easy,

    $('.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 that is implemented as part of the HTML 5 spec. It also requires server configuration to set up the App Cache manifest. It does not describe a method by which one can clear the 'traditional' browser cache via client- or server-side code, which is nigh impossible to do.

提交回复
热议问题