Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

configuring e-tags

Tags:

optimization

I am using Yslow as a simple speed benchmarking tool and I came across a really confusing concept. The E-tag

So the main problem is : How do I configure E-tags? my grade in yslow says:

There are 19 components with misconfigured ETags

* http://thehotelinventory.com/media/js/jquery.min.js
* http://thehotelinventory.com/media/js/jquery.colorbox.min.js
* http://thehotelinventory.com/media/js/easyslider.min.js
* http://thehotelinventory.com/media/js/jquery.tools.min.js
* http://thehotelinventory.com/media/js/custom.min.js
* http://thehotelinventory.com/media/js/jquery.validate.min.js
* http://thehotelinventory.com/media/images/colorbox/loading_background.png
* http://thehotelinventory.com/media/images/productheaderbg.jpg
* http://thehotelinventory.com/media/images/buttons/field-bg. //etc

I browsed through the developer.yahoo.com guidelines on website optimization yet I can't really understand the thing with e-tags

like image 998
yretuta Avatar asked Dec 02 '09 08:12

yretuta


People also ask

How do you make an ETag?

The method by which ETags are generated has never been specified in the HTTP specification. Common methods of ETag generation include using a collision-resistant hash function of the resource's content, a hash of the last modification timestamp, or even just a revision number.

What is ETag in HTML?

An ETag (entity tag) is an HTTP header that is used to validate that the client (such as a mobile device) has the most recent version of a record. When a GET request is made, the ETag is returned as a response header. The ETag also allows the client to make conditional requests.

What is ETag in REST API?

An entity tag, or ETag, is a mechanism that is provided by the HTTP protocol so that a browser client or a script can make conditional REST requests for optimistic updating or optimized retrieval of entities.

What is ETag in Apache?

ETag is a server response header that allows browsers to make conditional requests and perform cache validation efficiently. On the other hand, it poses security risks in case it gets leaked by your code, and can result in cache poisoning attack on your website.


6 Answers

This page shows how to disable ETags for IIS and this page shows how to do it for Apache.

like image 116
Bert Lamb Avatar answered Sep 29 '22 14:09

Bert Lamb


Assuming you are running Apache...

You can set up a simple ETag like this:

FileETag MTime Size

If you have multiple servers, you want to disable ETags.

FileETag None

Put the above code in your httpd.conf (if you have access), otherwise you can put it in .htaccess.

like image 32
philfreo Avatar answered Sep 29 '22 15:09

philfreo


Think of E-Tags as a sort of hash. When a browser makes a request for a resource, it sends along the E-tag of the file version it has cached. If the server decides that the files are similar enough (there are "strong" and "weak" versions of E-Tags so it's not always a simple comparison check) it will send a "304 Not Modified" response to the client, rather than the resource itself. This translates into a speed boost, since it prevents bandwidth from being wasted on unchanged files.

E-Tags are sent via HTTP headers.

There's a good example of E-Tags at work (and also how to disable them for Apache) here: http://www.askapache.com/htaccess/apache-speed-etags.html

like image 24
ShZ Avatar answered Sep 29 '22 15:09

ShZ


By removing the ETag header, you disable caches and browsers from being able to validate files, so they are forced to rely on your Cache-Control and Expires header.

Add these lines to .htaccess:

<ifModule mod_headers.c>   
Header unset ETag
</ifModule>
FileETag None
like image 36
Andrea Avatar answered Sep 29 '22 14:09

Andrea


Go straight to the source, YSlow provides guidance on all of it's advice, including how to configure ETags.

like image 34
Ben Marini Avatar answered Sep 29 '22 15:09

Ben Marini


The best way to configure your ETags is to remove them. For static files, far-future expiration dates are a much better approach.

The way to remove them depends on the web server you're using. For IIS 7, it can be done with a simple HttpModule.

like image 29
RickNZ Avatar answered Sep 29 '22 14:09

RickNZ