ETag

From IndieWeb


etag is a header sent in an HTTP response to allow future fetches of the same URL to be skipped if nothing has changed.

Why

When serving a URL that may be fetched multiple times (a feed or hovercard for example) it is good practice to send ETag and Last-Modified headers along with it in order to enable fetching code to optimize for reducing bandwidth from your site, and to theirs.

See https://pythonhosted.org/feedparser/http-etag.html for a discussion on how this can save you bandwidth.

How to

This section is a stub - please expand into a step-by-step How to inline!

If you're using static serving of files, sending ETag and Last-Modified headers is often done automatically by the web server using information from the host file system.

A client that supports this protocol will send back the ETag and If-Modified-Since headers when it next fetches your URL. Your web server will then check to see if there is a new version for them or not. If there is no change, it will return an HTTP 304 result and an empty body.

If you are dynamically generating your site, you have to do more work to create these headers yourself. Hashing is a common way to create an ETag; Last-Modified is a date in a standard format. You'll also need to check for them when serving.

The following are examples of how to do this for different languages

IndieWeb Examples

Most static site generators will naturally have ETag support, as webservers such as Apache and nginx come with ETag support out of the box for static files.

unmung uses ETag and Last-Modified to cache fetched pages for parsing - this was built for use with hovercards, as fetching and parsing several per page was slow. Now it prefers the cached version, and refetches if the ETag/last modified misses.

Publ uses the rendered content hash of a page as an etag, to improve caching behavior.

Pushl supports ETag and Last-Modified to determine if a page needs to be re-parsed and new notifications sent.

Criticism

  • Some websites have been found to use ETags to track users, by generating user-specific ETag headers for static assets (e.g. images) and using the If-None-Match header to track their subsequent accesses to that asset; this technique has been referred to as “super cookies” or cookieless cookies


See Also