过期头的解释
我有一个在 Apache 上运行的 joomla 应用程序。为了提高站点性能,我们在应用程序的根目录中编写了一个 .htaccess 文件,并为所有静态内容设置了一个远期过期标头。根据需要,文件第一次加载时会带有 200 状态代码。当再次单击同一链接时,许多文件直接从缓存提供。我需要解释两件事
当我按 f5 时,许多文件会加载 304 状态代码,但是我希望它们直接来自缓存,而不需要访问服务器获取状态标头?
当我关闭浏览器并再次返回同一页面时,我看到同样的事情发生,许多文件加载时带有 304 状态代码,尽管我认为它们会直接从浏览器缓存加载?
我知道 304 还提供来自浏览器缓存的文件,但我想避免服务器之间的标头通信,因为我的静态文件永远不会改变。另外我想补充一点,我的请求是通过 https 连接进行的,这会产生任何问题吗?
I have a joomla application working on Apache.To improve site performace we have written a .htaccess file to root of the application with setting a far future expires header to all the static content. As desired first time the files load in fresh with 200 status code. when again click on the same link many of the files are served directly from cache. I need explanation for two things
When i press f5 then a number of files load with 304 status code however i expected them to be coming directly from cache without hitting the server for a status header?
When i close the browser and come back to the same page again i see the same thing happening a number of files load with 304 status code although i thought they will load directly from the browser cache?
I understand that 304 also serves file from browser cache but i want to avoid the header communication between servers as my static files wont ever change. Also i want to add that my requests are over a https connection does that create any issue.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
浏览器具有根据过期时间发送缓存内容请求的算法。通常,具有遥远未来标题的内容永远不会像您期望的那样重新加载。但是,点击重新加载或 F5 会忽略这一点并强制重新加载所有页面内容。
要对此进行测试,您需要将光标放回地址栏(Win 上按 ALT-d)并按 Enter 键。这就像重新访问页面一样,浏览器的行为应该像您期望的那样。
Browsers have algorithms for sending requests for cached content, based on the expires time. Usually, content with a far future header will never be reloaded like you expect. But, hitting reload or F5 ignores this and forces a page reload of all page content.
What you want to do to test this is put your cursor back in the address bar (ALT-d on Win) and hit Enter. This is like re-visting the page and the browser should behave like you expect.
使用安全会话确实可能会导致缓存问题。
为了安全起见,许多浏览器不会缓存 SSL 数据,除非在 SSL 会话期间。当浏览器或选项卡关闭时,SSL 缓存将被刷新。
Firefox 有一个配置选项来控制它。我不知道IE。也可能有一些 Cache-Control 标头会覆盖此行为。
我相信 Cache-Control 标头是 HTTP/1.1,您应该使用它以及 Expires。 Cache-Control 提供了更多用于控制缓存的功能。
Using a secure session may indeed cause a problem with caching.
For security many browsers do not cache SSL data except during the SSL session. When the browser or tab is closed the SSL cache is flushed out.
Firefox has a config option to control this. I don't know about IE. It's also possible that there is some Cache-Control header that will override this behavior.
The Cache-Control header is, I believe, HTTP/1.1 and you should use it as well as Expires. Cache-Control offers more features for controlling the cache.