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.
关于如何在node.js中添加清单缓存的早期问题,我的问题现在与如何缓存node.js生成的HTML有关。因为我们没有像php(index.php)这样的物理文件,所以我们无法缓存这种文件。
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:
添加路由器以使用正确的mime-type返回cache.manifest文件:
app.get("/offline.manifest", function(req, res){
res.header("Content-Type", "text/cache-manifest");
res.end("CACHE MANIFEST");
});
在*找到
1 个解决方案
#1
3
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.
应缓存的缓存清单列表URL。访问这些URL的客户端不知道这些是Apache之上的静态html文件还是node.js或其他任何东西生成的动态内容。
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
阅读我的网址列表
浏览每个网址
下载响应并将其存储在安全的地方
检查我的cache.manifest是否已更改,然后继续执行步骤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.
因此,只要您通过URL可以访问node.js生成的数据,就可以将其定义为缓存清单中的一行。
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
如果你担心“我怎么知道有哪些url”你总是可以从node.js本身以编程方式生成cache.manifest文件 - 但是记得提供正确的内容类型text / cache-manifest
#1
3
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.
应缓存的缓存清单列表URL。访问这些URL的客户端不知道这些是Apache之上的静态html文件还是node.js或其他任何东西生成的动态内容。
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
阅读我的网址列表
浏览每个网址
下载响应并将其存储在安全的地方
检查我的cache.manifest是否已更改,然后继续执行步骤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.
因此,只要您通过URL可以访问node.js生成的数据,就可以将其定义为缓存清单中的一行。
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
如果你担心“我怎么知道有哪些url”你总是可以从node.js本身以编程方式生成cache.manifest文件 - 但是记得提供正确的内容类型text / cache-manifest