r/ProgrammerHumor • • Oct 08 '26

Meme atThisPointImTooAfraidTooAsk

Post image
4.4k Upvotes

86 comments sorted by

View all comments

Show parent comment

38

u/laplongejr Oct 08 '26 edited Oct 08 '26

Tbf I didn't test it myself (I'm not sure caniuse is specific enough for link parameters), but when I looked for old stackoverflow answers, it seemed the consensus was that link was not suited for scripts at all.
So I expect old browsers to break and new ones to have never tested it properly, especially as script tags became more and more complex over time.

[EDIT] Found a reliable source! (Thanks caniuse)

https://html.spec.whatwg.org/multipage/semantics.html#the-link-element
https://html.spec.whatwg.org/multipage/links.html#linkTypes

The possible supported tokens are alternate, dns-prefetch, expect, icon, manifest, modulepreload, next, pingback, preconnect, prefetch, preload, search, and stylesheet.

So using <link rel="script" would actually violate the HTML standard.
That's... sad.

13

u/Strict_Treat2884 Oct 08 '26 edited Oct 08 '26

I guess it's because JavaScript is synchronous (without defer or async ofc), it must be parsed and executed on the spot when constructing the webpage (mainly thanks to document.write?).

While <link> does't affect the document content itself, so it's meant to handle resourses that can be handled later. That's why JavaScript cannot be loaded by <link>, I reckon.

4

u/conundorum Oct 08 '26

Perhaps this could be solved by allowing <link urgent="true" script="whatever.js.your.boat">? Allow a tag to command the page to load and parse the script on the spot.

(Well, that or account for multipass parsing to load resources on one pass and execute them on the next, but that sounds like a nightmare for dynamically updated sites.)