Skip to content
Samuel Santos edited this page Jul 21, 2014 · 2 revisions

NoETagFilter is a Java Servlet filter that allows you to disable HTTP ETag headers set by most Java web containers.

From High Performance Web Sites: Rule 13 - Configure ETags:

Entity tags (ETags) are a mechanism that web servers and browsers use to determine whether the component in the browser's cache matches the one on the origin server. ETags were added to provide a mechanism for validating entities that is more flexible than the last-modified date. An ETag is a string that uniquely identifies a specific version of a component. The origin server specifies the component's ETag using the ETag response header.

The problem with ETags is that they typically are constructed using attributes that make them unique to a specific server hosting a site. ETags won't match when a browser gets the original component from one server and later tries to validate that component on a different server - a situation that is all too common on web sites that use a cluster of servers to handle requests.

The end result is ETags for the exact same component won't match from one server to another. If the ETags don't match, the user doesn't receive the small, fast 304 response that ETags were designed for; instead, they'll get a normal 200 response along with all the data for the component. If you host your web site on just one server, this isn't a problem. But if you have multiple servers hosting your web site your users are getting slower pages, your servers have a higher load, you're consuming greater bandwidth, and proxies aren't caching your content efficiently.

Sample configuration

NOTE: This configuration describes how to disable HTTP ETag header set by the DefaultServlet in Tomcat.

Declare the filter in your web descriptor file web.xml:

<filter>
    <filter-name>noEtag</filter-name>
    <filter-class>com.samaxes.filter.NoETagFilter</filter-class>
</filter>

Map the filter to Tomcat's DefaultServlet:

<filter-mapping>
    <filter-name>noEtag</filter-name>
    <servlet-name>default</servlet-name>
</filter-mapping>
Clone this wiki locally