Etag is a mechanism that HTTP provides for web cache validation, and allows a client to make conditional requests.
Working:
When a URL is retrieved, the web server will return the resource along with its corresponding ETag value. On the subsequent request, the server now compare the ETag value of the resource in the request with the ETag for the current version of the resource in the server. If the ETag values match, meaning that the resource has not changed, then the server send back a very short response with a HTTP 304 Not Modified status. The 304 status tells the client that its cached version is still good and that it should use that. However, if the ETag values do not match, meaning the resource has likely changed, then a full response including the resource's content is returned. In this case the client may decide to replace its previously cached version with the newly returned resource and the new ETag.
Note - If you are using a load-balanced server setup with multiple machines running Apache you will probably want to turn off ETag generation. This is because inodes are used as part of the ETag hash algorithm which will be different between the servers. You can configure Apache to not use inodes as part of the calculation but then you'd want to make sure the timestamps on the files are exactly the same, to ensure the same ETag gets generated for all servers.
Working:
When a URL is retrieved, the web server will return the resource along with its corresponding ETag value. On the subsequent request, the server now compare the ETag value of the resource in the request with the ETag for the current version of the resource in the server. If the ETag values match, meaning that the resource has not changed, then the server send back a very short response with a HTTP 304 Not Modified status. The 304 status tells the client that its cached version is still good and that it should use that. However, if the ETag values do not match, meaning the resource has likely changed, then a full response including the resource's content is returned. In this case the client may decide to replace its previously cached version with the newly returned resource and the new ETag.
Note - If you are using a load-balanced server setup with multiple machines running Apache you will probably want to turn off ETag generation. This is because inodes are used as part of the ETag hash algorithm which will be different between the servers. You can configure Apache to not use inodes as part of the calculation but then you'd want to make sure the timestamps on the files are exactly the same, to ensure the same ETag gets generated for all servers.
No comments:
Post a Comment