Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 216
user3658423 Avatar asked Jun 07 '15 01:06

user3658423


1 Answers

Jade has template pre-compiling and caching built in.

http://jade-lang.com/api/

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)
jade.renderFile('./templates/foo.jade');
like image 70
Andrew Lavers Avatar answered Sep 30 '22 00:09

Andrew Lavers