Home » Nodejs » How to active caching on Express – Node.js?

How to active caching on Express – Node.js?

Posted by: admin December 21, 2017 Leave a comment


how can i active the caching on Express to provide the pages quickly?

Thank you


You should only enable caching in production:

app.configure('production', function(){
  var oneYear = 31557600000;
  app.use(express.static(__dirname + '/public', { maxAge: oneYear }));

Furthermore you are probably better of using CDN or Nginx to host static files. A lot of CDN’s aren’t that expensive and I even found this free CDN at http://www.coralcdn.org/ thanks to stackoverflow.com. According to this blog post Nginx even has memcached to make your site extremely fast