HTTP状态代码200(缓存)与状态代码304之间有什么区别? [英] What is the difference between HTTP status code 200 (cache) vs status code 304?

查看:962
本文介绍了HTTP状态代码200(缓存)与状态代码304之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Google的Page Speed插件访问我的网站。

I'm using the Google "Page Speed" plug-in for Firefox to access my web site.

我页面上的某些组件表示为HTTP状态:

Some of the components on my page is indicated as HTTP status:

200
200(缓存)
304

200 200 (cache) 304

Google的页面速度。

By Google's "Page Speed".

我很困惑的是200(缓存)和304之间的区别。

What I'm confused about is the difference between 200 (cache) and 304.

我已多次刷新页面(但尚未清除我的缓存),似乎我的favicon.ico和一些图像的状态= 200(缓存),而其他一些图像是http状态304。

I've refreshed the page multiple times (but have not cleared my cache) and it always seems that my favicon.ico and a few images are status=200 (cache) while some other images are http status 304.

我不明白为什么差异。

更新

使用GooglePage Speed,我收到了 http:200(缓存) //example.com/favicon.ico 以及 http://cdn.example .com / js / ga.js

Using Google "Page Speed", I receive a "200 (cache)" for http://example.com/favicon.ico as well as http://cdn.example.com/js/ga.js

但是,我收到的http状态为304 http://cdn.example.com/js/combined.min.js

But, I receive a http status "304" for http://cdn.example.com/js/combined.min.js

我不明白为什么我有两个JavaScript文件位于同一目录/ js /中,一个返回http状态304而另一个返回200(缓存)状态代码。

I don't understand why I have two JavaScript files located in the same directory /js/, one returning a http status 304 and the other returning a 200 (cache) status code.

推荐答案

代码为200(缓存)的项目直接从您的浏览器缓存中完成,这意味着原始请求返回的项目带有标题,表明浏览器可以缓存它们(例如future-dated Expires Cache-Control:max-age headers),以及当你触发新的时候请求,这些缓存的对象仍然存储在本地缓存中并且尚未过期。

The items with code "200 (cache)" were fulfilled directly from your browser cache, meaning that the original requests for the items were returned with headers indicating that the browser could cache them (e.g. future-dated Expires or Cache-Control: max-age headers), and that at the time you triggered the new request, those cached objects were still stored in local cache and had not yet expired.

另一方面,304s是浏览器检查后服务器的响应如果文件自上一个版本缓存后被修改(答案为否)。

304s, on the other hand, are the response of the server after the browser has checked if a file was modified since the last version it had cached (the answer being "no").

为了获得最佳的网络性能,你最好设置一个远-future 到期: Cache-Control:max-age 所有资产的标题,然后当资产需要时更改,更改资产的实际文件名或将版本字符串附加到该资产的请求。这消除了对任何请求的需要,除非资产明确地从缓存中的版本改变(不需要304响应)。雅虎更多与缓存相关的性能指南,其中包括确保正确配置ETag。

For most optimal web performance, you're best off setting a far-future Expires: or Cache-Control: max-age header for all assets, and then when an asset needs to be changed, changing the actual filename of the asset or appending a version string to requests for that asset. This eliminates the need for any request to be made unless the asset has definitely changed from the version in cache (no need for that 304 response). Yahoo! has more cache-related performance guidelines, which include making sure that ETags are correctly configured.

这篇关于HTTP状态代码200(缓存)与状态代码304之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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