How to cache with manifest Node.js site

In relation with my early question of how to add manifest cache in node.js, my question now is related with how to cache the HTML generated by node.js. As we didn't have a physical file like in php (index.php) we cannot cache such kind of files.

How we can cache a "non existing" page? Just adding in cache:

    CACHE MANIFEST

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

Any idea of how to solve this problem?

Thanks!

Solution:

Add 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");
});

Found at stackoverflow


The cache manifest list URLs that should be cached. The client accessing those urls has no knowledge whether these are static html files on top of Apache or dynamic content generated by node.js or anything else.

You are basically instructing the client:

  • Read my list of urls
  • Go through each url
  • Download the response and store it someplace safe
  • Check back on my cache.manifest if it has changed and then proceed to step 1
  • So as long as your data generated by node.js is reachable via a URL there is no problem in defining it as a line in the cache manifest.

    And if you are worried "how will I know which urls there are" you can always generate the cache.manifest file programmatically from node.js itself -- but remember to serve the correct content-type text/cache-manifest

    链接地址: http://www.djcxy.com/p/10396.html

    上一篇: 如何在iPhone应用程序中使用正则表达式来分隔字符串,(逗号)

    下一篇: 如何缓存清单Node.js网站