▲ | jfagnani 2 days ago | |
You should use document.importNode() to clone templates. Template contents are in a separate document from the main document, which is what makes them inert. importNode() adopts the nodes into the document so they have the correct prototype immediately (which includes custom elements). Otherwise the adopt steps are run when the elements are first attached to the document, which adds another tree walk to the insert/append operation that costs some time. So:
Then you'll have a DocumentFragment you can pull nodes out of. Or just append the whole fragment. | ||
▲ | mholt 2 days ago | parent [-] | |
Awesome -- gonna try this. Thanks for the tip! And lit-html looks cool btw. Update: I'm using importNode() now -- works great too. |