[whatwg] HTML 5 Script Tag

Aryeh Gregor Simetrical+w3c at gmail.com
Thu Aug 6 16:48:47 PDT 2009


On Thu, Aug 6, 2009 at 7:14 PM, Cready, James<jcready at rtcrm.com> wrote:
> You make a great point. But whether or not you use the XML/XHTML <syntax/>
> or the HTML 4 <syntax> doesn¹t matter much. Since like I showed in my
> previous example: the instant you specify a src attribute on your opening
> <script> tag the browser will not execute anything inside the tags.
> Regardless of whether or not you even specified a value for it.

Yes, but if you use <script src=foo /> with no closing tag, the rest
of the page will be eaten, since it will be inside the script tag and
scripts' contents don't get displayed.  At least in some browsers.
Firefox 3.0 and 3.5 display this page with no title and no text:

<!doctype html>
<script src=foo />
<title>Test</title>
<p>Hello

Recentish WebKit does actually respect the self-closing part of the
<script> tag, and does display both the title and the text (but only
if the trailing / is present).  I'm pretty sure Firefox is correct
here according to the current HTML 5 spec, and WebKit is wrong, but I
haven't actually looked.  (Of course, the behavior in both cases
probably predates the spec.)

> I'm also curious as to why you're even allowed to specify an external src on
> a <script> tag.

Because <style> and <script> were invented at different times by
different groups of people, I'd assume.

> A) Allow <link> to pull in all types of external files:
>    CSS: <link rel="stylesheet" type="text/css" href="style.css" />
>    JS : <link rel="javascript" type="text/javascipt" href="script.js" />
> or
> B) Allow ONLY <script> and <style> to pull in their external files:
>    CSS: <style  src="style.css" type="text/css"></style>
>    JS : <script src="script.js" type="text/javascript"></script>

It wouldn't be unreasonable to introduce src="" for <style> for
consistency, and/or rel="script" for <link>.



More information about the whatwg mailing list