Mattias
Mattias

Reputation: 725

Does jade templates only need to be compiled once?

I am just starting to use jade with express.js and I'm trying to "get" jade.

My question is: Express says it caches jade in production, how does this work? Since the output depends on the input, does express check if the output will be the same?

Also, is NODE_ENV set to production automatically in production or do I have to manually set it?

Upvotes: 0

Views: 108

Answers (1)

robertklep
robertklep

Reputation: 203359

Before Jade can generate HTML is has to read the template from file, parse it and build some sort of internal representation. The result from all those steps, a compiled template, will be cached (the idea being that templates in production environments aren't supposed to change, so it's safe to load and compiled them just once).

Express will then use the cached compiled template to generate the output, based on the input. This is a step that's always performed, so the output isn't what's being cached.

As for the environment variable: you're supposed to set NODE_ENV=production manually, or as part of your deployment scripts.

Fwiw, you can always override template caching from your Express app:

var app = express();
...
app.set('view cache', true);
...

See this table for other application settings.

Upvotes: 1

Related Questions