How to cache using Node.js manifest

In connection with my early question on how to add manifest cache in node.js, now my question is related to how to cache HTML generated using node.js. Since we did not have a physical file such as php (index.php), we cannot cache such files.

How can we cache a "nonexistent" page? Just adding a cache:

CACHE MANIFEST CACHE: # plain files to cache /javascripts/client.js /stylesheets/style.css /stylesheets/style.styl # generated files like / / /content 

Any idea on how to solve this problem?

Thanks!

Decision:

Add a router to return the cache.manifest file with the correct mime type:

 app.get("/offline.manifest", function(req, res){ res.header("Content-Type", "text/cache-manifest"); res.end("CACHE MANIFEST"); }); 

stack overflow

+7
source share
1 answer

The URLs of the cache manifest list that should be cached. The client accessing these URLs does not know if they are static html files on top of Apache or dynamic content generated using node.js or something else.

Basically you instruct the client:

  • Read my address list
  • Go through each URL
  • Download the answer and save it in a safe place.
  • Check back my cache.manifest file if it has changed, then go to step 1

As long as your data created using node.js is reachable using a URL, there is no problem defining it as a string in the cache manifest.

And if you are worried β€œhow do I know what URLs are”, you can always generate the cache.manifest file programmatically from node.js, but remember to specify the correct content type text/cache-manifest

+3
source

All Articles