O'Reilly logo

Mastering Web Application Development with Express by Alexandru Vlăduțu

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

View caching in production

During development, it's useful to be able to make changes to the templates, refresh the browser, and see the new changes without having to reload the server.

However, when the application enters production, you would not want the template files to be read over and over again with each page load, because that would decrease throughput considerably.

The view cache setting and its effect

Express automatically enables the view cache setting when run in production mode, as shown in the following source code snippet:

if (env === 'production') {
  this.enable('view cache');
}

We can enable that flag by ourselves using app.enable('view cache'). This might be useful at times when we want to stress test our application, for example, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required