BF50 Black Friday · 50% off all plans
from $5/mo · Auto-applied ---:--:-- Claim 50% off →
Skip to content

Search Seonio

Type a keyword, domain, or paste a URL

Start free with $1 to see full results. Powered by Seonio
Web Development

ETag: The HTTP header that validates caches

An ETag is an HTTP response header that names one version of a file. Browsers and crawlers send it back, and your server answers 304 if nothing changed.

Monthly searches · etag
110.0k
Keyword research data
etag
ETag: The HTTP header that validates caches
Click the image to view it full size

An ETag, short for entity tag, is an HTTP response header that labels one specific version of a file at a URL. The value is any string in double quotes that the server chooses, often a hash of the content or a version number:

ETag: "33a64df551425fcc55e4d42a148795d9"

When the file changes, the server must give it a new ETag. That lets a browser, a CDN or a crawler ask a cheap question later: "I have the version called 33a64…, is it still current?" If it is, the server says so without sending the file again.

How an ETag check works

This check is called revalidation. It happens when a cached copy has gone stale, meaning its Cache-Control lifetime has run out:

  1. The first response carries the file and its ETag. The browser stores both.
  2. Later, the browser asks for the same URL and sends the stored value in an If-None-Match header.
  3. The server compares that value with the current ETag.
  4. If they match, the server answers 304 Not Modified with no body, and the browser reuses its copy. If they differ, the server sends the new file with a 200 status and the new ETag.
GET /styles.css HTTP/1.1
If-None-Match: "33a64df551425fcc55e4d42a148795d9"

HTTP/1.1 304 Not Modified
ETag: "33a64df551425fcc55e4d42a148795d9"

A 304 skips both the download and, if your server is smart about it, the work of building the response.

ETags have a second job outside caching. When someone saves an edit, the client can send If-Match with the ETag it last saw. If another person saved a change in between, the values won't match, and the server answers 412 Precondition Failed instead of letting one edit silently overwrite the other.

Strong and weak ETags

An ETag is strong by default. A W/ prefix makes it weak:

ETag: W/"0815"
  • A strong ETag promises the bytes are identical. Caches need it to store range requests, where a client fetches part of a large file.
  • A weak ETag promises only that the content is equivalent, for example the same page with a different timestamp in a comment. It's easier to generate for dynamic pages.

For the usual cache check with If-None-Match, the HTTP standard uses weak comparison, so W/"0815" and "0815" count as a match. For If-Match edits, only strong ETags can match.

ETag or Last-Modified?

Last-Modified does the same job with a date, and browsers send it back in If-Modified-Since. Dates are simpler but coarse: they only resolve to the second, and they break when files are copied or deployed with new timestamps. The HTTP standard notes that an ETag can be more reliable in those cases. If a request carries both headers, the server must ignore the date and use the ETag.

Google's advice is to use ETag, and to set both if you can.

What ETags mean for SEO

Google's crawlers support both kinds of conditional request. In a December 2024 post, Google wrote that when its crawler sends an ETag back and the value still matches, your server should return a 304 with no body. That saves your server the work and the bandwidth. Google also noted how rarely sites allow this: about 0.026% of its fetches were cacheable 10 years earlier, and 0.017% at the time of writing.

This is a crawling matter, not a ranking one. Google's post says that for a large site whose pages rarely change, allowing caching may help it crawl the site more efficiently. Google suggests changing the ETag only for significant changes: a new copyright year in the footer probably doesn't count.

Where ETags go wrong

  • The value never changes. If the ETag stays the same after an edit, browsers and crawlers keep the old version. Make sure the value comes from the content or a version number that changes on every deploy.
  • The value changes on every request. Pages that embed a timestamp, a random token or an ad slot get a new hash each time, so a 304 never happens. Hash only the stable content, or use a weak ETag.
  • Several servers, several values. Apache, for example, builds file ETags from the modification time and size by default. If your servers hold copies with different timestamps, the same file gets different ETags depending on which server answers.
  • Compression changes the value. By default, Apache's compression module adds a suffix to the ETag of compressed responses. Its documentation notes that this prevents 304 responses for compressed content. Check the setting if your 304 rate looks low.
  • Missing quotes. The value must be in double quotes. ETag: abc123 is invalid.

Check your own ETags

Fetch a file and look at the headers:

curl -I https://www.example.com/styles.css

Then send the ETag back and confirm you get a 304:

curl -I -H 'If-None-Match: "33a64df551425fcc55e4d42a148795d9"' https://www.example.com/styles.css

For how caching fits together, see cache.

SEO wiki

Related terms

More definitions from the same corner of SEO and digital marketing.

Seonio

Put it to work on your own site

Keyword research, traffic, backlinks and clustering in one place. Start with a free $1 to test, no card required.