使用 Nunjucks 进行异步模板预加载

Async template preload with Nunjucks

Nunjucks 使用getTemplate()预加载和预编译模板-

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

文档也说 "If using any async loaders, you must use the async API." 但没有任何代码示例。谁能告诉我使用什么代替 getTemplate 进行异步预加载?

来自他们的文档: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);
    }
});