我正在将我的 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/