Reputation: 528
Normally, when using EJS templates with Express, I don't have to restart the server to see changes I've made to a template. I just make a change to a .ejs file and reload the browser to see my changes.
However, with swig templates (which I very much prefer over ejs), if I make a change to a .html file, I have to restart the server inorder to see my changes reflected in the browser.
Is this a bug, or just a side effect of something else I've overlooked?
I'm not looking for a tool like grunt watch, nodemon, or supervisor, I just want my swig templates to behave more like ejs templates if possible.
Upvotes: 6
Views: 2918
Reputation: 203359
As explained in the Swig API Documentation, you can configure Swig to not cache templates.
I use something similar to this:
swig.init({
..
cache : app.get('env') === 'production',
..
});
This will make it only cache compiled templates in the production environment.
Upvotes: 7
Reputation: 20315
generally, there are two steps to templates. the first is "compiling" where the template is converted into a function, then there's "rendering", where the function is just executed with local variables.
for ejs and most templating systems, compiling is done on every request during development. however, with swig, it's probably always caching the compilation step even though express says "DON'T CACHE WHEN NOT IN PRODUCTION", so the "function" doesn't change until you restart.
solution? ask swig, tell them to support enabling/disabling caching in https://github.com/visionmedia/consolidate.js
Upvotes: 0