[whatwg] HTML 5 Script Tag

Markus Ernst derernst at gmx.ch
Fri Aug 14 01:42:33 PDT 2009


Tab Atkins Jr. schrieb:
> On Thu, Aug 6, 2009 at 6: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.
> [snip]
>> It seems like there should be some consistency between the two, either:
>>
>> 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>
> 
> I (and others in this thread, and probably a lot of people on the web
> as a whole) agree with you that it would be nice to have some
> consistency there (I favor the <link> approach myself).  However, the
> world is neither kind nor just, and one of HTML5's explicit guidelines
> is to codify and standardize browser behavior in the wild.  We can
> improve it when it's possible to do so in a backwards-compatible way,
> but otherwise it's out.

The favored example:

<link rel="script" type="text/javascript" href="script.js">

would actually not break pages in legacy browsers, unless their 
functionality depends on the script. They would just not find and thus 
not execute the script, and possibly throw "function does not exist" 
errors.

Authors are encouraged to code web pages in a way that the functionality 
is provided, or at least degrades nicely, in no-script environments. So 
I assume that a properly coded page would work or degrade nicely in 
legacy browsers with the <link> syntax. Anyway I am not sure about this, 
as I am aware of the fact that a missing script file is not the same as 
a user agent without script execution. At least the following example 
would work in Firefox - if the foo() function is not defined, 
otherpage.php will be called:

<a href="otherpage.php" onClick="return foo()">Click here</a>


More information about the whatwg mailing list