Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Template html and template string in web components

Is it better to use html template (and then html import) to create web components or to use template string? What are pros and cons of these methods?

like image 724
asv Avatar asked Aug 11 '26 22:08

asv


1 Answers

Using html template files is better for reuse: the same file can be used in different web components. Also they are better displayed in most IDEs as they are recognized as full HTML code.

Using template strings is faster (inline). They don't rely on HTML Imports which is not adopted by every browser vendors. Also you can use template literals to insert directly value of JavaScript variables in the DOM.

Actually there's no much diffrences because there's a workaround for every differences list above (i.e. you can reuse template strings if you save them as text file, or you can load html templates withour HTML imports).

like image 90
Supersharp Avatar answered Aug 14 '26 22:08

Supersharp



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!