小编ene*_*ebe的帖子

如何使用清单Node.js站点进行缓存

在与我的关系,早期的问题,如何在node.js中添加清单高速缓冲存储器,我现在的问题是与如何缓存由node.js中生成的HTML相关 因为我们没有像php(index.php)这样的物理文件,所以我们无法缓存这种文件.

我们如何缓存"不存在"的页面?只需添加缓存:

    CACHE MANIFEST

    CACHE:
    # plain files to cache
    /javascripts/client.js
    /stylesheets/style.css
    /stylesheets/style.styl
    # generated files like /
    /
    /content
Run Code Online (Sandbox Code Playgroud)

知道怎么解决这个问题吗?

谢谢!

解:

添加路由器以使用正确的mime-type返回cache.manifest文件:

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

在stackoverflow找到

node.js cache-manifest

7
推荐指数
1
解决办法
6801
查看次数

NodeJS undefined var获取错误

我希望这是一个非常简单的问题,但我无法理解为什么不工作.

我的问题是,我访问了一个可能未定义的变量.

这是功能:

  app.get('/loc', function (req, res) {

    if (typeof req.user.userId === 'undefined'){
        redirect('/');
    } else {
        var userId = req.user.userId;
        Loc.getP([userId], function(promos) {
           res.render('local/index', {
            title: 'Local'
          });   
        });
    }
  });
Run Code Online (Sandbox Code Playgroud)

问题在于我正在检查var是否未定义.如果没有,我只想重定向到其他网址.如果已定义,则呈现用户的数据.很简单,但总是我尝试访问req.user.userId我得到以下内容:

500 TypeError: Cannot read property 'userId' of undefined
Run Code Online (Sandbox Code Playgroud)

我尝试了我在互联网上找到的所有东西,但我认为在JS中它必须工作......

任何的想法?谢谢!

node.js

0
推荐指数
1
解决办法
2万
查看次数

标签 统计

node.js ×2

cache-manifest ×1