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?
相关问题
- Angular RxJS mergeMap types
- Google Apps Script: testing doPost() with cURL
- How to instantiate Http service in main.ts manuall
- C#使用http访问网络,有办法用指定网卡访问网络嘛?
- PHP Empty $_POST
相关文章
- C#使用http访问网络,有办法用指定网卡访问网络嘛?
- netcore3中,在OnResultExecuted方法中,怎么读取Response内容
- Is a unicode user agent legal inside an HTTP heade
- Is there a google API to read cached content? [clo
- git: retry if http request failed
- Flutter - http.get fails on macos build target: Co
- C# HttpClient.SendAsync always returns 404 but URL
- AWS API Gateway caching ignores query parameters
Unless stated as weak by the server, an ETag is considered a strong validator, and can thus be used to satify a conditional ranged request. However, most automatically generated ETags exhibit difficulties in server farm situations, since they often use inode information and / or a unique persistent counter. In practice, I have found the Last Modified header to be sufficient for fairly static content, e.g. serving up protected static content, since the write time of the file makes a reasonably good validator.
The ETag is by far the most flexible. Conforming clients are required to send the ETag in a conditional request, whereas they SHOULD send both if available.
The If-Modified-Since header is used to specify the time at which the browser last received the requested resource. The If-None-Match header is used to specify the entity tag that the server issued with the requested resource when it was last received.
In the two ways described, these headers are used to support caching of content within the browser, and they enable the server to instruct the browser to use a cached copy of a resource, rather than responding with the full contents of the resource if this is not necessary.
Regarding the differences between
Last-Modified/If-Modified-Since
andETag/If-None-Match
: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.
Examples:
mtime
as theLast-Modified
date is the simplest solution.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:
If-Modified-Since uses a date, while If-None-Match uses an ETag. They can both be used for "pages" (i.e. HTML) and other files.
As it is stated in google's best practices :
https://developers.google.com/speed/docs/best-practices/caching
If-Modified-Since
is compared to theLast-Modified
whereasIf-None-Match
is compared toETag
. BothModified-Since
andETag
can be used to identify a specific variant of a resource.But the comparison of
If-Modified-Since
toLast-Modified
gives you the information whether the cached variant is older or newer whereas the comparison ofIf-None-Match
toETag
just gives you the information whether both are identical or not. Furthermore do most of theETag
generators include the information of the system specific inode so moving a file to a different drive may change theETag
as well.