Skip to content

Implement HTM without eval, with optional mini version - #62

Merged
jviide merged 27 commits into
developit:masterfrom
jviide:megamix
Feb 25, 2019
Merged

jviide merged 27 commits into
developit:masterfrom
jviide:megamix

Conversation

@jviide

@jviide jviide commented Jan 30, 2019 •

Copy link
Copy Markdown
Collaborator

This pull request combines the modifications from PRs #53 and #59. Compared to the master it adds two major features:

  • Support for multiple root elements: When the template has two or more root elements the return value is an array. Relevant tests are added.
  • Support for stricter Content Security Policies: No strings are eval'd as code.

The major difference from PRs #53 and #59 is that the library can be compiled in two modes based on the flag MINI (maybe settable with the feature suggested at developit/microbundle#312). When MINI=false (the default) the compiled library resembles the one from #53. The library uses Map for caching when available, and otherwise falls back to the caching scheme used by the current master branch. The resulting library size is smaller compared to the current master, and faster when benchmarked with the perf-test-harness branch (although modified to use tagged templates whenever possible).

The master version:

639 B: htm.mjs.gz
584 B: htm.mjs.br
703 B: htm.umd.js.gz
647 B: htm.umd.js.br

Creation: 15,827/s, average: 63µs
Usage: 534,997/s, average: 1µs

The MINI=false version:

591 B: htm.mjs.gz
540 B: htm.mjs.br
654 B: htm.umd.js.gz
584 B: htm.umd.js.br

Creation: 80,528/s, average: 12µs
Usage: 712,561/s, average: 1µs

When MINI=true the library is compiled like #59: the results are directly evaluated without caching. The library is then much slower, but the resulting size is small:

421 B: htm.mjs.gz
376 B: htm.mjs.br
490 B: htm.umd.js.gz
432 B: htm.umd.js.br

Creation: 80,830/s, average: 12µs
Usage: 57,042/s, average: 17µs

@jviide jviide changed the title Megamix Implement HTM without eval, with optional mini version Jan 30, 2019
@jviide

jviide commented Jan 30, 2019

Copy link
Copy Markdown
Collaborator Author

Note: I merged the branches from #53 and #59 just to keep the history for this PR.

@developit

Copy link
Copy Markdown
Owner

+1 to your git-fu, history of these implementations is important since to document how you evolved this over the past month 👍🧙‍♂️

@jviide
jviide requested a review from developit February 22, 2019 00:09
@jviide
jviide merged commit 8d14f03 into developit:master Feb 25, 2019
@jviide
jviide deleted the megamix branch February 25, 2019 18:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants