Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

if-modified-since vs if-none-match

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?

like image 968
Tower Avatar asked Jun 15 '09 22:06

Tower


People also ask

What is the purpose of if-modified-since?

The If-Modified-Since request HTTP header makes the request conditional: the server sends back the requested resource, with a 200 status, only if it has been last modified after the given date.

What does if-none-match mean?

The If-None-Match HTTP request header makes the request conditional. For GET and HEAD methods, the server will return the requested resource, with a 200 status, only if it doesn't have an ETag matching the given ones.


1 Answers

Regarding the differences between Last-Modified/If-Modified-Since and ETag/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:

  • If you're serving files, using the file's mtime as the Last-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
like image 77
trendels Avatar answered Sep 22 '22 02:09

trendels