if-modified-since vs if-none-match [英] if-modified-since vs if-none-match
问题描述
if-modified-since和if-none-match之间可能有什么区别?我有一种感觉,if-none-match用于文件,而if-modified-since用于页面?
What could be the difference between if-modified-since and if-none-match? I have a feeling that if-none-match is used for files whereas if-modified-since is used for pages?
推荐答案
关于 Last-Modified / If-Modified-Since
和 ETag / If-None-Match
之间的差异:
两者都可以互换使用。然而,取决于资源的类型,以及它在服务器上的生成方式,一个或另一个问题(自......以来这已被修改?/这仍然与此ETag相匹配吗?)可能更容易回答。
Both can be used interchangeably. However depending on the type of resource, and how it is generated on the server, one or the other question ("has this been modified since ...?" / "does this still match this ETag?") may be easier to answer.
示例:
- 如果您正在提供文件,请使用该文件
mtime
因为Last-Modified
日期是最简单的解决方案。 - 如果你正在服务一个由许多SQL查询构建的动态网页,检查这些查询返回的数据是否已经改变可能是不切实际的(除非它们都有某种最后修改列)。在这种情况下,使用例如页面内容的md5哈希作为
ETag
将会容易得多。
OTOH,这意味着你仍然必须生成整个页面服务器,即使是有条件的GET。找出究竟要进入ETag的内容(主键,修订号,......等)可以为您节省大量时间。
- If you're serving files, using the file's
mtime
as theLast-Modified
date is the simplest solution. - If you're serving a dynamic web page built from a number of SQL queries, checking whether the data returned by any of those queries has changed may be impractical (unless all of them have some sort of "last modified" column). In this case, using e.g. an md5 hash of the page content as the
ETag
will be a lot easier.
OTOH, this means that you still have to generate the whole page on the server, even for a conditional GET. Figuring out what exactly has to go into the ETag (primary keys, revision numbers, ... etc.) can save you a lot of time here.
有关该主题的更多详细信息,请参阅以下链接:
See these links for more details on the topic:
- http://www.tbray.org/ongoing/When/200x/2008/08/14/Rails-ETags
- http://bitworking.org/news/150/REST-Tip-Deep-etags-give-you-more-benefits
- http://www.tbray.org/ongoing/When/200x/2008/08/14/Rails-ETags
- http://bitworking.org/news/150/REST-Tip-Deep-etags-give-you-more-benefits
这篇关于if-modified-since vs if-none-match的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!