防止移动 Safari 缓存溢出
我有一个简单的小型网络应用程序,它聚合了我家周围一些支持以太网的摄像机的几个视图。这基本上是一个小仪表板,这样我就可以轻松地知道房子周围发生了什么。我通过将 new Date().getTime() 附加到基本 URI 来经常刷新图像。
一切都很顺利,除了一个小问题之外,日子过得很愉快。如果我将仪表板留在 iPad 上一段时间,它就会耗尽内存并崩溃回到主屏幕。我知道这是因为 Mobile Safari 将这些图像缓存在 RAM 中,最终导致图像数量过多。
由于这些图像托管在嵌入式设备上;我真的没有能力直接修改缓存标头。我也想远离在我的服务器端制作包装器。
我的问题是;谁能想出一种方法来防止 Mobile Safari 过度缓存这些图像以致崩溃?
I've got a simple little web app that's aggregating a couple views from some ethernet enabled cameras around my house. This is basically a little dashboard, so that I can easily tell what's going on around the house. I've got it refreshing the images every so often by appending new Date().getTime() to the base URI.
Everything works happy days, except for one little issue. If I leave the dashboard up on my iPad for awhile, it runs out of memory and crashes back to the home screen. I know that its because Mobile Safari is caching each of these images in RAM and it eventually ends up with far too many of them.
Since these images are being hosted on embedded devices; I really have no ability to modify the caching headers directly. I would like to stay away from making a wrapper on my server side as well.
My question is; can anyone think of a way to prevent Mobile Safari from caching these images so aggressively that it crashes?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在删除图像之前,您可以尝试重用
img
标签和/或将src
属性设置为空字符串。导致移动 Safari 崩溃的可能不是激进的缓存,而是浏览器在图像标签被删除时无法很好地处理释放图像引用的问题。您可能会在这里找到更多有用的信息:
http://www.vargatron.com/2010/08/ ipad-html5-js-内存管理/
You might try to reuse your
img
tags and/or set thesrc
attribute to an empty string before removing an image. It's probably not an aggressive cache that's crashing mobile safari, but how the browser doesn't deal well with releasing image references when image tags get deleted.You might find more useful information here:
http://www.vargatron.com/2010/08/ipad-html5-js-memory-management/