If Modified Since HTTP Header

if-modified-since

What Does If Modified Since Header Do?

The if modified since HTTP header indicates the time for which a browser first downloaded a resource from the server. This helps determine whether or not the resource has changed since the last time it was accessed. If the HTTP status of a particular resource is 304 Not Modified, this means that the file has not changed and there is no need to download it again. Having this ability allows both the website owner and visitor to conserve resources as the file does not have to be retrieved each time.

Why Does it Matter?

Googlebot crawls billions of pages resulting in a large amount of resources used to index each page on the Internet. If a particular page has not been modified since the last time Google crawled it, there is no need for Google to download that file again, thus it can move on to the next. This helps improve efficiency and save bandwidth at the same time.

However, do not mistake this as an incentive to save bandwidth by purposely not updating / adding new content to your site. Yes, Googlebot is going to use some bandwidth to crawl your site but in most cases this is fairly minimal. Adding new content, making your site faster, getting more links to your site, etc. are all great ways to move up in the SERPs. The more Googlebot crawls your site, the better it will be for your website’s SEO. The status 304 code simply helps improve the efficiency when a bot crawls your site.

How Does it Work?

A conditional GET request is at the basis of how a if modified since header works. When a conditional request is made for a particular resource, the client provides the server with the Last-Modified date of its cached copy by using the if modified since header.

The server then determines based on these headers if the client’s cached copy is the most recent version of this file. If so, the server returns an HTTP status 304 code, letting the client know it can reuse it’s cached copy.

If the the client does not have a cached copy (i.e it is the first time visiting the resource), the resource must be downloaded from the origin server, resulting in an HTTP code 200. Similarly this code will also be returned for requests that have an outdated version of a resource stored in cache thus requiring the latest resource to be fetched from the server.

Example

KeyCDN’s WordPress Cache Enabler also makes use of the HTTP 304 if modified since header. It does so to help browsers determine if the content of a particular page has changed since the creation of the static HTML file.

As can be seen upon initial load of the KeyCDN support page, an HTTP status code of 200 is shown for the HTML document. In this case there was no cached copy in the browser cache, therefore the HTML file was retrieved from the origin server.

HTTP-status-200

Upon refresh, the browser realizes that the file has already been downloaded thus the browser sends the if modified since header back to the server. As can be seen by the image below, the server evaluated it’s copy and the browser’s cached copy and determined that there have been no changes since the last download, resulting in a 304 Not Modified.

HTTP-status-304

Conclusion

Knowing what the if modified since HTTP header does, helps give you a better understanding of what efficiency measures are being taken to make the web faster. Having the ability to use a cached copy of a resource can without a doubt save time for the user and makes the process of crawling webpages more efficient for search engines.