admin管理员组

文章数量:1415655

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.

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.

Share Improve this question edited May 18, 2010 at 10:16 abitgone asked May 14, 2010 at 15:09 abitgoneabitgone 56110 silver badges30 bronze badges 6
  • 1 Independently whether this is actually possible (I doubt it), when is a browser cache considered full, since it's basically a queue where the oldest data is deleted, when space is needed. Or when is it not full? Being not full would require the user to regularly empty it, what the majority of people never do... – RoToRa Commented May 14, 2010 at 15:15
  • 3 I'm curious how and why you determined that a full cache was the issue, as opposed to conflicting data in the cache or some such thing. Anyhow, if you're the same person that got a lot of abuse on p.lang.javascript (groups.google.co.uk/group/p.lang.javascript/browse_thread/…), I hope you get better treatment on stackoverflow... – Colin Pickard Commented May 14, 2010 at 15:21
  • Heh... no, that wasn't me on p.lang.javascript. What I suppose I'm really asking is what GMail is doing to detect that your browser's cache is full, and to show this message to our end users. Via your link, and through a quick read, I managed to find this discussion (groups.google./group/p.lang.javascript/browse_frm/thread/…) which explains what is likely going on, and how to do it. Thanks! – abitgone Commented May 14, 2010 at 15:29
  • @RoToRa: I suppose what we're actually trying to detect is not whether or not the cache is full (like you, I'm not sure it's actually possible to do this, hence the question) 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 as if its cache is full. – abitgone Commented May 14, 2010 at 15:40
  • It looks like the gmail cache-is-full warning is only displayed via http. I've read reports that the message goes away when browsing gmail with https. Source – David Murdoch Commented May 14, 2010 at 15:50
 |  Show 1 more ment

3 Answers 3

Reset to default 6

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. (e.g. is slower)
  2. If the browser cache contains invalid data (e.g. 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 (e.g. 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 (e.g.)
    • http://example./scripts/latestThing.js?ver=3425
    • where the "ver" is pulled from your versioning system to ensure you always force the browser to download a fresh copy any time you change your script.
  • 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 (e.g. your JS Library files (e.g. 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?
};

Consider sending a header to have your application never cache your content and to have it expire immediately.

本文标签: javascriptDetecting if a browser39s cache is fullStack Overflow