r/ProgrammerHumor • • Oct 08 '26

Meme atThisPointImTooAfraidTooAsk

Post image
4.4k Upvotes

86 comments sorted by

View all comments

415

u/ApprehensiveGas85 Oct 08 '26 • Bravo

<link rel="stylesheet" href="..."> actually follows proper HTML/SGML architecture, because <link> was built specifically for external document relationships before CSS even existed.

Netscape broke the pattern when they rushed out Navigator 2.0 and slapped src directly onto <script>. Both <style> and <script> should have stayed purely as container tags for inline code, while external JavaScript should have always been loaded through <link rel="script" href="...">.

The real inconsistency isn't that <style> is missing a src; it's that external JavaScript should have been a <link rel> from day one.

69

u/Mateorabi Oct 08 '26

Does the “correct” way work too at least even if everyone uses the expedient way?

75

u/laplongejr Oct 08 '26

I am 99% sure it actually doesn't

43

u/ChesterWOVBot Oct 08 '26

The 1% is one specific minor version of a niche browser with a userbase of 2 people in total.

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.)

19

u/wokeboogeyman Oct 09 '26

I propose that all tags should be updated to support a src= instead

15

u/GatotSubroto Oct 09 '26

<div src="…"> 🤔

11

u/The_Neto06 Oct 09 '26

Sure why not

4

u/gringrant Oct 09 '26

<br src="…">

2

u/HugoNikanor Oct 11 '26

Sure, but since <br/> can't have content, that link better point to nothing

1

u/gringrant Oct 11 '26

Content-Length MUST be 0

5

u/HugoNikanor Oct 11 '26

RFC 9110 (HTTP) specifies that:

A user agent SHOULD NOT send a Content-Length header field when the request message does not contain content and the method semantics do not anticipate such data

So I feel a better semantic would would a 204 (No Content) response, which would remove the need for a content-length header altogether.

13

u/metaglot Oct 08 '26

Also feels clumsy to have a closing tag for script when youre using the src-attribute.

5

u/Mr_Carlos Oct 09 '26

Okay but the CSS one is always a minor pain. After 20+ years of making websites I never remember it, I always just copy it from another website.

JS used to require meta tags, but HTML 5 removed that requirement (and many more), so it would have been nice to address external CSS and simplify it.

2

u/MrEpic382RDT Oct 08 '26

Netscape 2 didn’t have external scripts; those didn’t become a feature until Netscape 3