Cache static pages and content nodejs

Hazem Hagrass Source

I have a static content to cache using nodejs, as far I know there are two ways:

  1. This can be done using nodejs:

    app.use(express.static(path.join(__dirname, 'public'), { maxAge: oneDay }));

  2. Add x.appcahe file with static contents to cache, then add manifest attribute in html tag:

    <html manifest="x.appcache">

So my question is what is the diffrence between both ways?

javascripthtmlhtml5node.js

Answers

answered 4 years ago Matthew Bakaitis #1

  1. In the first, the node.js server is setting the Cache-Control header using express.js functionality.
  2. In the second, the HTML specifies a manifest to be cached by the browser.

If you search for "cache-control vs html manifest" you'll find a TON of details that exceed what can be written by me in a single answer. However, this other question titled HTML 5 Cache Manifest Vs. Etags, Expires or cache-control header has a great summary and to quote

The main differences between the HTML5 cache manifest vs. the traditional HTTP headers:

  • for the cache manifest you need support in the browser
  • for the HTTP headers you also need support in the browser of course but it's more universal
  • you have more control over the caching with cache manifest
  • your website or Web app can work correctly offline with no connection at all
  • you can have two version of every resource - for offline and online usage

The last point is very handy and lets you easily swap parts of your website that need connection with eg. placeholders containing optional comments that the user doesn't get full functionality without the connection or whatever you want.

There are also some compatibility issues because some browsers don't always play according to the standards...so that's also worth researching and determining which (cache-control vs manifests) is best for your situation.

comments powered by Disqus