HTTP Etag caching

Etag (or entity tag) is one of the caching mechanisms in HTTP. In fact, it’s an identifier that is assigned to the file by the server for further inspection. http etag

When a client requests a web page files (images, CSS, etc.), the server sends all the data with Etag as:

HTTP/1.1 200 OK
Server: MyServer/2.1
Date: Thu, 09 Jun 2016 13:30:54 GMT
Content-Type: text/html
Accept-Ranges: bytes
Last-Modified: Tue, 07 Jun 2016 12:00:00 GMT
ETag: "6d82cbb050ddc7fa9cbb659014546e59"
Content-Length: 363

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "">
<html xmlns="">

# An example of the server response with Etag

Files are cached on the client side, and when the browser requests these files again, the request is supplemented with If-None-Match string:

GET /news/latest.html HTTP/1.1
If-None-Match: "6d82cbb050ddc7fa9cbb659014546e59"

# Example request with Etag

The server, in turn, checks Etag, if it matches, the server sends a response code 304:

HTTP/1.1 304 Not Modified
Server: MyServer/2.1
Date: Tue, 07 Jun 2016 09:00:00 GMT
ETag: "6d82cbb050ddc7fa9cbb659014546e59"
Content-Length: 0

# Specifies that the files have not changed, and browser can take them from the cache

Otherwise, the required files will be re-sent.

Enable Etag

All modern web browsers and web servers support HTTP Etag. To activate it in Nginx you need to edit the configuration file:

server {
	location ~* ^.+\.(rss|atom|jpg|jpeg|gif|png|ico|rtf|js|css)$ {
		expires 2592000;
etag on;

# Etag enables for static files

The most important

HTTP Etag can increase the responsiveness of web applications and reduce bandwidth consumption. The function is supported by all modern web browsers and does not require additional configuration after enabling.

Подпишитесь на Хайлоад с помощью Google аккаунта
или закройте эту хрень