Jump to content

Question about <script>


HTML5

Recommended Posts

Why is an external link to a javascript file defined as

<script type="text/javascript" src="myjavascript.js"></script>

and not in a <link> tag like css?

Link to comment
Share on other sites

So the browser can tell the difference between CSS and Javascript. Also because javascript is commonly known as a "script". I doubt there's any real technical reason.
If that was the reason, then they might as well have let the <style> element have a src attribute for consistency, and let developers only use "link" for "unknown" at the time of writing stuff, such as favicons and RSS feed links.I'm guessing the only reason we have the link in a script element is because of the browser wars at the time - JavaScript was originally a Netscape extension, and they put it out for standartization only after implementing it in their browser (as Microsoft also did with their own extensions). There were no namespace mechanisms, so Netscape poisoned the global namespace by calling the hook element "script", and when standartization came, the W3C WG probably said "well... it's already implemented like that... probably not so good puristically speaking, but it works... anyone against? Microsoft? No? You've already implemented it like that? Oh, OK.".
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...