Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tips and tricks #81

Open
alexewerlof opened this issue Aug 15, 2020 · 0 comments
Open

Tips and tricks #81

alexewerlof opened this issue Aug 15, 2020 · 0 comments
Labels

Comments

@alexewerlof
Copy link
Owner

alexewerlof commented Aug 15, 2020

Tips and tricks

To put in the wiki or in the code

Security

Template compilation and interpolation is a resource consuming task.
The algorithms in most template engines (including regular expression matching) runs in synchronous mode and can block the event loop. Blocking the event loops can lead to:

  • Janky UI in the frontend
  • Inaccessible server on the backend

Use worker threads if you know that your templates are going to be large or contain too many paths.

Parsing the template can be particularly resource consuming (even for a light library like Micromustache). There are multiple options available to put a limit on how the template is parsed.

Multi-level processing

This one is very important because one of the main use cases (and its original reason for existence) for MicroMustache is internationalization and it's common for i18n templates to require multi-level interpolation. Demo a real use case with the i18n.js example.

Performance

Use paths like a.b.c instead of a['b']['c'] because it is much faster to parse.

If it is possible compile the template once and reuse the results.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant