Skip to content

ETag

Medium — good to knowBackend

ELI5 — The Vibe Check

An ETag is like a fingerprint for a response. The server sends it with the response, and next time the client asks for the same thing, it sends the ETag back. If the fingerprint matches, the server says '304 Not Modified — use your cached copy.' Saves bandwidth and speed.

Real Talk

An ETag (Entity Tag) is an HTTP response header containing a hash or version identifier for a resource. Clients send the ETag back via If-None-Match headers on subsequent requests. If the resource hasn't changed, the server returns 304 Not Modified without a body, reducing bandwidth. ETags enable conditional requests and optimistic concurrency control.

Show Me The Code

// Server sets ETag
res.setHeader('ETag', '"abc123"');

// Client sends on next request
// If-None-Match: "abc123"

// Server checks and returns 304 if unchanged
if (req.headers['if-none-match'] === currentETag) {
  return res.status(304).end();
}

When You'll Hear This

"ETags save bandwidth by telling the client 'nothing changed, use your cache.'" / "Our API uses weak ETags for list endpoints and strong ETags for individual resources."

Made with passive-aggressive love by manoga.digital. Powered by Claude.