r/javascript • u/Xadartt • 4d ago
Inline rendering with document.currentScript
https://leanrada.com/notes/inline-rendering-currentscript/1
u/jessepence 4d ago
If you made this a custom element, it would remove 90% of the boilerplate.
C'mon, it's <this-year></this-year>1
u/RudePhilosopher5721 3d ago
That’d also add 300% overhead…
If you actually read the article, it’d be more apt to say you might replace it with a custom element of <template></template> instead of their proposed shorthand of $()
That is of course if that weren’t already an element…
3
u/jessepence 3d ago
Lol, I read the article, big dog.
300% overhead? Are you sure? Did you measure that?
Are you certain that one script defining the custom element and re-using it throughout the website wouldn't be fewer overall bytes and easier for the browser to render than multiple script tags littered throughout the page that need to be synchronously, individually rendered and cannot be deduplicated?
How would the use of a template element be mutually exclusive to this solution in any way?
2
u/Disastrous-Town-4820 3d ago
300% is impressive precision for a benchmark running in the comments
would like to see a trace of both with the same number of instances, then click while they're being created. the bytes went down, sure, but someone still has to build those nodes and it isn't the network