DEV Community

loading...

Are native html reusable templates a thing?

leewynne profile image lee ・1 min read

Hypothetically speaking, if you are building a web app using just plain html, css and JS (no frameworks) do developers use reusable html components using the tag?

I understand that in Rails there are partials and in JS frameworks there are components etc.

I am just curious to hear what has been used in the past for native html,css & js at scale.

Discussion (2)

pic
Editor guide
Collapse
nicozerpa profile image
Nico Zerpa (he/him) • Edited

I've used the <template> tag last year, but just a couple of times. If I decided to create a web app without frameworks, I think I'd use them quite heavily, together with custom elements. But I'd definitely miss the declarative style of UI libraries like React or Vue.js.

But in the past, most of the heavy lifting was made on the server-side, the front end was mostly used to display the HTML contents that the server created dynamically. JavaScript engines were slower and the language itself had fewer features.

Collapse
ogranada profile image
Andres Granada • Edited

According the MDN reference (developer.mozilla.org/en-US/docs/W...) a template is a way to put html code that won’t be rendered unless you extracted and make it rendereable using JavaScript.

I think it is a way to give a sort of hierarchy and order to your vanilla projects and avoid to parse a lot of strings (with a parser or using innerHTML) in your JavaScript code.