user3658423 user3658423 - 4 months ago 101
Node.js Question

node.js/Jade - How to pre-compile jade files and cache it?

Framework: node.js / express.js / Jade

Question: in production env, when a jade file is rendered by express, jade cache's it so future renders are faster.

When I start node.js app, how can I pre-compile (or) pre-render (like warmup) all the jade files so its already in cache when requests start to come in...

I can use a folder recursion, I just need to know how to pre-compile (or) pre-render.

Is this possible?


Jade has template pre-compiling and caching built in.

Simply specify cache: true option to jade.compileFile, and iterate through all of your template files.

var options = {cache: true};

// iterate/recurse over your jade template files and compile them
jade.compileFile('./templates/foo.jade', options);

// Jade will load the compiled templates from cache (the file path is the key)