Async template preload with Nunjucks

422 views Asked by At

Nunjucks uses getTemplate() to preload and precompile templates -

env.getTemplate('page.html', true);

Documentation says also "If using any async loaders, you must use the async API." but there's no any code example. Can anyone tell what to use instead of getTemplate for async preload?

1

There are 1 answers

0
Joshua Terrill On BEST ANSWER

From their docs: Just add an async: true property to your loader and it will be used asynchronously.

https://mozilla.github.io/nunjucks/api.html#asynchronous

var MyLoader = nunjucks.Loader.extend({
    async: true,

    getSource: function(name, callback) {
        // load the template
        // ...
        callback(err, res);
    }
});