How to programmatically empty browser cache?

前端 未结 11 1010
迷失自我
迷失自我 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 17:44

    On Chrome, you should be able to do this using the benchmarking extension. You need to start your chrome with the following switches:

    ./chrome --enable-benchmarking --enable-net-benchmarking 
    

    In Chrome's console now you can do the following:

    chrome.benchmarking.clearCache();
    chrome.benchmarking.clearHostResolverCache();
    chrome.benchmarking.clearPredictorCache();
    chrome.benchmarking.closeConnections();
    

    As you can tell from above commands, it not only clears the browser cache, but also clears the DNS cache and closes network connections. These are great when you're doing page load time benchmarking. Obviously you don't have to use them all if not needed (e.g. clearCache() should suffice if you need to clear the cache only and don't care about DNS cache and connections).

提交回复
热议问题