问题描述
下面提供的答案.
我花了几天的时间来理解为什么 Mozilla Firefox 总是无法从其缓存中检索图像,而不是每次我重新加载页面时都获取新副本.
I've struggled for a couple of days to understand why Mozilla Firefox continually failed to retrieve images from its' cache as opposed to fetching new copies everytime I reloaded a page.
Google Chrome 似乎没有这个问题,但这是因为在 Chrome 中刷新页面不会强制它重新加载图像(除非使用 CTRL-F5).
Google Chrome didn't appear to have this issue, but that's because refreshing the page in Chrome does NOT force it to reload images (unless a CTRL-F5 is used).
下面我已经回答了我自己的问题并添加了一些额外的信息,我希望可以帮助其他人节省一些时间来解决这个问题.
Below I've answered my own question and added some extra info that I hope will save someone else some time in getting their head around this issue.
推荐答案
谢谢kapep,好建议.不确定如何将问题表述为问题 - 但我可以回答我自己的问题!
Thanks kapep, good advice. Wasn't sure how to phrase as a question - but answering my own question I can do!
首先要确保图像是可缓存的,您必须检查响应标头以确保将以下标头设置为有效值:
First of all to ensure an image IS cacheable you must inspect the Response Headers to ensure the following headers are set to valid values:
- Cache-Control"设置为私有或公共.
- 'Expires' 是一个以正确格式表示的未来日期.(例如,格林威治标准时间 2012 年 6 月 21 日星期四 06:20:49)
- Last-Modified"不比Date"标头更新.
- 'Content-Disposition' 未设置为附件";
如果您确信标头设置正确,但图像似乎仍未从缓存中到达,请确保以下几点:
If you're convinced the headers are set correctly and it still seems like the images aren't arriving from the cache, ensure the following:
- 您不是 F5 刷新页面来检查缓存,因为如果您刷新,Firefox 将获取图像的新副本.确保您通过导航到另一个页面并重新访问同一页面来重新加载您的页面(这将是您的一个用户的正常行为).
- 在您的 about:config 中(只需在地址栏中输入即可访问隐藏设置) browser.cache.memory.enable = true 和 browser.cache.disk.enable = true
这篇关于为什么 Firefox 似乎没有缓存图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!