Tuesday, October 28, 2008

ETags

I'm sure your all familiar with ETags, which can be used to determine if you've downloaded a file from a site or not. This works great for images: if you've already downloaded an image, why bother downloading it again? But have you ever thought of using ETags to determine if a user has downloaded your dynamic html?

Let's say you've got a page that takes 15 database queries to generate. I'd bet money on the fact that with just one or two of those queries you could determine, using ETags, whether or not the user has seen the page already. If you can do that, you can return a response code of 304 (Unmodified), so the browser pulls everything from cache -- you'll cut database activity and bandwidth usage to a fraction of what they would be otherwise, which could cut the need for extra servers in your cluster.

Here is a cool blog entry using RoR as an example, but the same technique applies with Grails (and Java):

and here is another more long winded article with Spring/Hibernate


-Dustin