Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 343
abitgone Avatar asked May 14 '10 15:05

abitgone


1 Answers

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.com/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)
like image 63
scunliffe Avatar answered Sep 28 '22 11:09

scunliffe