4 ms·
I do stuff like this regularly: <div>…</div><script>document.currentScript.previousSibling.…</script> Provided you care even vaguely about code size (and ar
by chrismorgan 3y ago
I do stuff like this regularly:
<div>…</div><script>document.currentScript.previousSibling.…</script>
Provided you care even vaguely about code size (and are ending up with handfuls of kilobytes at most, not multiple megabytes), inlining everything is excellent for performance (seriously, unreasonably effective, way more than most expect), and if it’s stuff that must be done before the document is fully interactive, then doing it immediately like this rather than messing around with DOMContentLoaded event handlers and querying and such is likewise excellent for performance.
- 8n4vidtmkvmk 3y agoYeah I think I was doing something similar. The scripts can safely be executed as soon as the HTML/DOM is in there, no need to defer to the end.