0

From what I see in the docs, when you use the render api and pass a third argument for a callback, calls to render should be async, not sync, yet when I do this client-side:

nunjucks.render("template.html", data, function(err, res) {
    $("#resultDiv").html(res);
});

It is still doing a sync xhr request. (To be clear, it renders just fine, but it isn't an async call.)

Raymond Camden
  • 10,661
  • 3
  • 34
  • 68
  • 1
    Looking at the library code, it appears this is the intended behavior. If you follow the `render` call's path, you will get to [this comment](https://github.com/mozilla/nunjucks/blob/master/src/web-loaders.js#L59) in the code. I think the answer to your question would likely be to override this loader in some form or fashion (fork the repo, monkey-patch it, etc) – barry-johnson Apr 13 '15 at 19:29
  • 1
    Makes sense. The docs seem to try to cover both Node.js and client-side storage, but in this case, it seems like they aren't clear that this form of the API is *always* sync for client-side. If you put this in the Answers, I'll approve it/vote it up/etc. – Raymond Camden Apr 13 '15 at 21:24

1 Answers1

1

Since no better answer showed up overnight and you requested it, my answer from the comments is:

Looking at the library code, it appears this is the intended behavior. If you follow the render call's path, you will get to this comment in the code. I think the answer to your question would likely be to override this loader in some form or fashion (fork the repo, monkey-patch it, etc).

barry-johnson
  • 3,204
  • 1
  • 17
  • 19