What’s a good method of programatically generating etag for web pages, and is this practice recommended? Some sites recommend turning etags off, others recommend producing them manually, and some recommend leaving the default settings active – what’s the best way here?
What’s a good method of programatically generating etag for web pages, and is this
Share
ETags do help when you use some kind of caching mechanism in front of your website-generator. Browsers themselves do not use them, they listen to ‘(if) modified since’ or ‘age’ header structs, afaik.
Anyway, due to its simple nature it is no problem to provide a http-header with an ETag. I heard that many web servers simply take the location of the file and the timestamp of the file and do a md5-hash over this data.
We, as an example, built a simple but effective etag with our software. Every ‘content unit’ (i.e. html, jpegs, gifs…) in our software has a unique id and a version number (i.e. a jpeg has the id ’17’ and version ‘2’, this means it was changed once). So the ETag simply is the string ‘id-version’, here: ’17-2′. With the next change it would be ’17-3′ so that the cacher recognizes the change, loads the new content part (once) completely and stores it in it’s own cache.
But you could probably use the URL and a timestamp (i.e. the timestamp of the file), too.