Validating standard input

The Cache-Control header was defined as part of the HTTP/1.1 specification and supersedes previous headers (for example, Expires) used to define response caching policies.

All modern browsers support Cache-Control, so that's all you need.

The only thing left to do is to ensure that the server is providing the necessary ETag tokens.

Check your server documentation for the necessary configuration flags.

However, that’s inefficient because if the resource hasn't changed, then there's no reason to download the same information that's already in cache!

That’s the problem that validation tokens, as specified in the ETag header, are designed to solve.

If the token hasn't changed, the server returns a "304 Not Modified" response, which tells the browser that the response it has in cache hasn't changed and can be renewed for another 120 seconds.

Unfortunately, the browser can't use the previous response because the response has now expired.

At this point, the browser could dispatch a new request and fetch the new full response.

When the server returns a response, it also emits a collection of HTTP headers, describing its content-type, length, caching directives, validation token, and more.

For example, in the above exchange, the server returns a 1024-byte response, instructs the client to cache it for up to 120 seconds, and provides a validation token ("x234dff") that can be used after the response has expired to check if the resource has been modified.

Leave a Reply