简体   繁体   中英

Detecting if a browser's cache is full

We've identified that full browser caches are the cause of a problem on our extranet. It only affects a small number of our users, but we'd like to alert them to the problem and give them some guidance on how to fix the problem for themselves.

We'd like to use a similar system to the one which GMail uses. When it detects that your browser's cache is full is not behaving as it should, it shows a warning message telling users that their cache is full and that it may cause problems with GMail, along with a link to a Gmail Help page on clearing your browser's cache .

Does anyone know if there any resources out there, or examples of how to use JavaScript to detect that the browser's cache is full behaving badly?

Thanks.


Clarification: What we're actually trying to detect, I suppose, is not whether or not the cache is full, but rather whether a script, which we have configured server-side to be stored in the cache, is being re-requested from the server - in such a way that the browser is behaving strangely, or as if its cache is not behaving as it should.


Further Clarification: Thank you all for the updates on caching. Our scripts are being sent with the correct headers, and we're only seeing this problem in IE6 and IE7 - Mozilla and WebKit browsers seem to be unaffected - but I'm still not sure on how exactly we'd go about using JavaScript and/or XmlHttpRequest to check to see whether or not an object was retrieved from the cache, thus letting us check whether the cache is behaving badly.

The browser's cache will not cause problems if it is full... with a few minor notes.

  1. If the browser cache is full, the browser simply has to download fresh content vs. pulling it from its local cache. (eg is slower)
  2. If the browser cache contains invalid data (eg an old copy of a JavaScript file) then yes, you may encounter issues. (not because the cache is full, but because you didn't serve up a fresh file for the user (Google for: expires headers and how to alter the URL path to your files when you make script changes to ensure you "break" the cache))
  3. In Internet Explorer, when you push a download file (eg an Excel spreadsheet) to the user it must go into the cache to work (an IE bug) - I'm not sure if the file is bigger than the users' total cache, if that causes issues with the file being stored, and therefore loaded (Stackers pls feel free to confirm if this one way or another)

Update: Based on your clarification, you need to ensure that any script you send to the client is appropriately cached... which means:

  • Change the URL to your scripts when you want a new version to be downloaded (eg)
  • Once you are sure that the URL changes, you can send cache headers that tell the browser to cache the files for a very long time (eg your JS Library files (eg jQuery) likely don't change every hour, day, week or even month)

This will probably not work as is. But its just an idea:

var img = new Image();
(new Image).src = "imageWithFarFutures.png";
window.onload = function(){
    document.getElementById("someIframe").src = "imageWithFarFutures.png";
    // NOW if the server DOES get a FRESH request for "imageWithFarFutures.png"
    // wouldn't it mean that the browser has kicked it out of its cache?
};

考虑发送一个标题,让您的应用程序永远不会缓存您的内容并让它立即过期。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM