Node.js 快速应用程序缓存/页面加载缓慢(swig 模板引擎)

标签 node.js caching express swig-template

我正在将我的 apache 站点(在 bluehost 上)移动到 node.js(在 heroku 上),并且注意到它的运行速度相当慢。我想知道这是否是缓存问题或者我可能做错了什么。

这是 Heroku 上的网站:http://ak-web-prod.herokuapp.com/

这是bluehost上的网站:http://ardentkid.com

如果您注意到,在浏览网站时,页面有时会在加载过程中闪烁白色(这就是为什么我认为这可能是缓存问题)。我已设置快速配置:

app.enable('view cache');

似乎没有改变任何事情。大家有什么想法吗?

这是我的应用程序配置

app.configure(function(){
    app.set('config', config);
    app.set('views', __dirname + '/views');
    app.set('view engine', 'html');
    app.set('db', db);
    app.set('port', process.env.PORT || 3000);
    app.engine('.html', cons.swig);
    app.use(express.logger('dev'))
    app.use(express.favicon(__dirname + '/public/img/favicon.ico'));
    app.use(express.cookieParser())
    app.use(express.bodyParser()) //enables req.body
    app.use(express.methodOverride()) //enables app.put and app.delete (can also just use app.post)
    app.use(express.session({
        secret: 'topsecret'
        , store: new RedisStore({
              client:db
            , secret:config.db.auth
            })
    }));
    app.use(passport.initialize()) // use passport session
    app.use(passport.session())
    app.use(app.router) // routes should be at the last
});

app.configure('development', function(){
    console.log('app in development mode');
    app.use('/assets', express.static(__dirname + '/public'));
    app.use('/', express.static(__dirname + '/'));
    swig.init({root: __dirname + '/views', allowErrors: true, cache: false});
    app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
});

app.configure('stage', function(){
    console.log('app in development mode');
    app.use('/assets', express.static(__dirname + '/public', { maxAge: 86400000 }));
    app.use('/', express.static(__dirname + '/', { maxAge: 86400000 }));
    swig.init({root: __dirname + '/views', allowErrors: true, cache:true});
    app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
});

app.configure('production', function(){
    app.enable('view cache');
    app.use('/assets', express.static(__dirname + '/public', { maxAge: 86400000 }));
    app.use('/', express.static(__dirname + '/', { maxAge: 86400000 }));
    swig.init({root: __dirname + '/views', cache:true});
    app.use(express.errorHandler());
});

最佳答案

问题是由于我的 redis 数据库(在 RedisToGo 上)无法正确连接。我不认为这会影响页面加载,但它确实会影响。现在它已修复,该应用程序比以往任何时候都更快!

关于Node.js 快速应用程序缓存/页面加载缓慢(swig 模板引擎),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15726023/

相关文章:

javascript - 全局变量在 NodeJS 中不起作用未定义

javascript - Node.js 不同函数之间的全局变量

caching - Grails 不会加载在静态资源中所做的更改(除非重新启动)

javascript - 在线托管 node.js 项目

javascript - 无法从 React 前端向 Node.js 后端发送 POST 请求

node.js - AngularJS 注入(inject)器和 NodeJS 之间的区别 require 模块

javascript - 解释connect session中的length和clear session store方法

arrays - Node.js - 从函数返回数组

php - ob_start 缓存 CSS

css - 性能,一次性提供所有CSS,还是根据需要提供?