What is the difference between ETag and Last-Modified?

In the world of web development, website performance is crucial. Caching is a vital mechanism used by web servers that improves the performance of a website to optimize user experience. It allows browsers to store and reuse resources, reduce server requests and improve website speed.

Caching reduces the loading time of websites
Caching reduces the loading time of websites

Two important HTTP headers, ETag and Last-ModifiedThe server sends the date and time of the last modification done in the resource in response to the request. This header is used with another caching header (such as If-Modified-Since)., play a key role in caching. While both headers contribute to caching strategies, they have distinct characteristics and serve specific purposes. Understanding the difference between ETag and Last-Modified headers empowers web developers to enhance caching techniques and fine-tune website performance.

ETag vs. Last-Modified

ETag

Last-Modified

Unique identifier for each modification in the resource

Timestamp of the last modification in the resource

Used with the If-None-Match header

Used with the If-Modified-Since header

More accurate results

Less accurate results

Performs better when frequent modifications are expected in the resource’s content

Does not perform well when frequent modifications are expected in the resource’s content

Conclusion

In conclusion, ETag and Last-Modified headers serve distinct purposes in web communication and caching. ETag provides precise information by generating a unique ID for each change to the resource’s content. In contrast, Last-Modified indicates the general timestamp of the last modification but might not capture the fine-grained changes accurately, especially in cases of frequent modifications.

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved