concept ETags in category hapi

appears as: ETags
hapi.js in Action

This is an excerpt from Manning's book hapi.js in Action.

In this section we’re going to look at working with client-side caching with hapi. First, I’ll show you how to manually set headers with hapi. Then I’ll show you a convenient feature in hapi that lets you control cache headers by setting policies in configuration. Finally, we’ll take a look at ways of dealing with revalidation and ETags.

hapi will calculate and set ETags for you automatically only when using the file and directory handlers from Inert. You might want to use ETags in other cases too. We see ETags used in some JSON APIs such as Facebook’s Graph API and Github’s API. The benefits here are the same. An API client can avoid downloading a whole new resource if it has an efficient way to revalidate a previously cached response.

If you want to set ETags for non-file responses, you’ll have to manage setting them yourself. Rather than manually setting the ETag header and managing the If-None-Match comparison yourself, hapi has the convenience method response.etag().