检测浏览器的缓存是否已满 [英] Detecting if a browser's cache is full

查看:183
本文介绍了检测浏览器的缓存是否已满的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们发现完整的浏览器缓存是导致我们的外部网络出现问题的原因。它只影响到我们的一小部分用户,但我们想提醒他们这个问题,并给他们一些关于如何解决问题的指导。



我们希望使用类似GMail使用的系统。当它检测到您的浏览器的缓存已满时表现不如其应有的行为时,它会显示一条警告消息,告诉用户缓存已满,并且可能会导致GMail出现问题, Gmail帮助页面清除浏览器的缓存



有人知道是否有任何资源,或者如何使用JavaScript来检测浏览器的缓存是否满足行为不佳的示例?



谢谢。




澄清:我想,我们实际上试图检测的不是缓存是否已满,而是正在重新向服务器请求一个脚本(我们已将服务器端配置为存储在缓存中) - 以这种方式,浏览器行为奇怪,或者如果它的缓存没有像它应该那样行事。






进一步说明:谢谢大家关于缓存的更新。我们的脚本正在使用正确的标题发送,而我们在IE6和IE7中只能看到这个问题 - Mozilla和WebKit浏览器似乎没有受到影响 - 但我仍然不确定我们会如何使用JavaScript以及/或XmlHttpRequest来检查是否从缓存中检索到对象,从而让我们检查缓存是否表现不佳。

浏览器的缓存 不会 ,如果它已满,则会产生问题......并附带一些小记录。


  1. 如果浏览器缓存已满,浏览器只需下载新内容,并将其从本地缓存中提取出来即可。 (例如速度较慢)

  2. 如果浏览器缓存中包含无效数据(例如JavaScript文件的旧副本),那么可能会遇到问题。 (不是因为缓存已满,而是因为您没有为用户提供新的文件(Google for: expires headers >以及如何将URL路径更改为您的文件,当你修改脚本以确保你中断缓存时))

  3. 在Internet Explorer中,当你向用户推送下载文件(例如Excel电子表格)时,它必须进入缓存工作(IE错误) - 我不确定文件是否大于用户的总缓存,如果这导致文件存储问题,并因此加载(Stackers pls随时确认这种或那种方式)

更新:
根据您的说明,您需要确保您发送给客户端的任何脚本恰当缓存......这意味着:


  • 当您想要下载新版本时,将URL更改为您的脚本(例如)


    • http://example.com/scripts/latestThing.js?ver=3425

    • 其中ver被拉从您的版本控制系统开始,确保您始终强制浏览器在您更改脚本时下载新的任何时间


    • 确定URL发生更改后,您可以发送缓存标头,告诉浏览器缓存文件很长一段时间(例如您的JS库文件(例如jQuery)可能不会每小时,每天,每周甚至每月更改)


    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. (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.)
    • 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)

    这篇关于检测浏览器的缓存是否已满的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆