←back to thread

217 points palmfacehn | 2 comments | | HN request time: 0s | source
Show context
EGreg ◴[] No.45107545[source]
What exactly is the point of <template> tag? Just to create document fragments? I mean that’s all you can really do with it in HTML. If you are using JS you can attach shadow dom to any element.

I guess maybe slots for web components is the other point?

replies(4): >>45107642 #>>45108238 #>>45109718 #>>45111635 #
acdha ◴[] No.45107642[source]
I’ve used it to have the server generate fragments not processed in the normal page load which are then used as templates by JavaScript which populates them. That supported fast initial page loads compared to an SPA while being just as dynamic after being loaded.

This worked pretty well but definitely had some rough edges which I really wish the standards process could’ve focused on. Things like JSX are so much slower / memory intensive but people use them for convenience and it’d be nice to improve the ease-of-use story.

replies(1): >>45113262 #
1. mikojan ◴[] No.45113262[source]
Could you not achieve the same with a <div hidden>?
replies(1): >>45137343 #
2. Doxin ◴[] No.45137343[source]
<template> tags don't do anything to their contents. You can for instance have an <img> tag in there without the image getting loaded, or a <script> tag which doesn't get executed.