how to enable cache with http etag on server

Caching with HTTP Etag

1 Shares
1
0
0

An Etag (or entity tag) is one of the caching mechanisms in HTTP. It is essentially an identifier that the server assigns to a file for later inspection.

http etag cache schema

When a client requests web page files (images, CSS, etc.), the server transmits all the data along with Etag tags in the form:

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

…

# Server response example

The files are stored in the client-side cache, and when the browser requests these files again, an If-None-Match string is added to the request:

GET /news/latest.html HTTP/1.1

If-None-Match: “6d82cbb050ddc7fa9cbb659014546e59″

Host: example.com

# Server response example

The server, in turn, checks the Etag and if it matches, the server responds with a 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

# Indicates that the files have not changed and can be taken from the cache

Otherwise the required files will be resent.

How to enable Etag on server

All modern web browsers and web servers support HTTP Etag. To enable this feature on Nginx, you need to edit its configuration file:

server {

…

location ~* ^.+.(rss|atom|jpg|jpeg|gif|png|ico|rtf|js|css)$ {

expires 2592000;

etag on;

}

…

}

# enable Etag for static files

Conclusions

HTTP Etag allows you to increase the responsiveness of your web application and reduce the channel load. The feature is supported by all modern web browsers and requires no additional configuration once enabled.

1 Shares
4 comments
  1. How do I check if the etag cache is enabled on the server? What is the best way to check the http-response of the server to check http etag cache enabled or not?

    1. You can use web-developer extension for google chrome or other browser. Here is the link https://chrome.google.com/webstore/detail/web-developer/bfbameneiokkgbdmiekhjnmfkcnldhhm?hl=en

      This extension allows you to view response headers in one click and there you can check etag cache status.

  2. How do I know what type of server I’m using? In order to activate the etag cache.

    1. Write to your ISP to find out the type of server if you cannot find this information in the admin panel. You can also ask tech support to simply activate the etag cache for your site.

Leave a Reply

Your email address will not be published. Required fields are marked *

You May Also Like