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.
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, but run it in a different environment mode (other than production).
Let's make a sample application using Jade that displays a list of users. We will check its throughput with the view cache
setting disabled first and then with it enabled.
We will...