Node Js & HTTP Caching

I've come to realise that I know very little about caching.

I recently downloaded the Node JS Connect ST middleware module, but am at a loss for ideas on how to use the caching features. I think that's partly due to my ignorance about how both client and server side http caching works.

In an ideal world, I'd like to:

  • Have the server hold all commonly requested files in RAM.
  • Serve a web page and all of it's assets to a client.
  • Have the client cache both the markup and the assets.
  • Only make a request for an entire file, if it's found to have been changed on the server.
  • Render a cached file on the client when the file is found to be unchanged on the server.

I thought I'd be able to use etag headers or the 'if-last-modified' header to effect this process. Unfortunately, it doesn't work like this in practice, as the average browser appears not to relinquish it's cache after the initial visit. To force it to behave as expected, I've read that I'd need to:

  • Serve markup files with 'no-cache' headers.
  • Change the name of every asset file that needs to be updated on the client.

If this is the case, what is the point of the "etag" and "if-last-modified headers'? Is there any way to utilise them to invalid the browser cache?

And another question, more specific to the ST module... How should I go about serving the markup without caching, but the assets with caching? Will I need to create two ST Cache objects for each set of files/folders?