W3C home > Mailing lists > Public > www-html@w3.org > November 2003

RE: <link> vs. <script> for external scripts

From: Ernest Cline <ernestcline@mindspring.com>
Date: Tue, 18 Nov 2003 14:22:32 -0500
Message-ID: <410-2200311218192232828@mindspring.com>
To: "Andy Holmes" <aholmes84@shaw.ca>
Cc: "W3C HTML List" <www-html@w3.org>

> [Original Message]
> From: Andy Holmes <aholmes84@shaw.ca>
> A couple of people were having a discussion on IRC the other day
> about  the fact that <script> is used with a 'src' attribute to include 
> external scripts rather than the link element. It seems to me more 
> consistent and logical to use <link> for external resources like this 
> and <script> for in-document scripts, such as <style> and <link> have a 
> relationship for stylesheets.
> The only thing that is actually missing for <link> to be properly used 
> is the 'script' link-type. The 'src' attribute on the <script> element 
> could probably be deprecated if this link-type was added since it 
> wouldn't be necessary anymore.
> Comments?

You know, this element, as it is defined has a number of anomalies
in it.. First off, the type attribute applies to the both the contents
and to the accessed resource.  It also interacts differently with
remote stuff.  Let me give some examples to show what I mean.

Example 1:
<script type="image/png" src="example1">
  So do we show a picture or what?

Example 2:
<script type="image/png">
  Is the user agent supposed to try to interpret this as
  some sort of inline data?

Example 3:
<span type="text/javascript" src="example3">
  Does this span element get treated  the same
  as a script element would?

Based on these three examples, I think we need to 
redefine how the script element is defined for XHTML2.

It needs a different attribute than type to indicate the
MIME type of the contents for the element.

This would allow the following to be legal:

<script datatype="text/javascript" type="image/gif" src="flashing_logo">
  // And here goes a script that if the UA doesn't support animated GIFs
  // would try to replicated the effect via scripting.

Whether this use case is desirable is a separate question. :)

It has some other advantages besides allowing generic embedding.
Since type is not a required attribute in general, but needs to be
for script (and for style as well) so using a separate attribute seems
preferable, especially if type allows fro multiple types to be indicated.
Received on Tuesday, 18 November 2003 14:25:22 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 7 January 2015 15:06:06 UTC