views:

54

answers:

5

I am reading through the XHTML 1.0 Strict Doctype and found out that there's a value of "script" for the rel attribute on the link element.

<link rel="script" href="..." />

I tried using this tag to link external JS files, but Safari does not even load the file. So what can the tag be used for?

Update:

After rereading the DTD, it doesn't exactly list out valid values for the rel attribute. The 'script' value appears only as an example on a comment. Thus, this may or may not be implemented in all browser.

A: 

External js files are usually loaded with the <script> tag:

<script type="text/javascript" src="/foo.js"></script>
Darin Dimitrov
I do believe so, yeah. :D But I am asking about the usage of this link element, not how to embed external JS file.
Adrian Godong
This is not standard. Haven't seen any site using `<link` to include external js files. Any particular reason you would like to do this?
Darin Dimitrov
This is a written standard, you probably mean "not common"? I'm just curious over what it can be used for. For example, when I'm writing my own browser.
Adrian Godong
Yes, sorry, I meant not common, my English is very bad :-)
Darin Dimitrov
Mine too, especially after Friday night. :)
Adrian Godong
+1  A: 

The link element is there to convey relationship information between the page being viewed and the content of the element.

From the spec:

Although LINK has no content, it conveys relationship information that may be rendered by user agents in a variety of ways

So, informational only.

Oded
I am reading XHTML 1.0, and it says it can be used for "c) to make a link to a script (rel="script")". But it doesn't.
Adrian Godong
@Adrian Godong - can you please provide a link to where this is written?
Oded
http://www.w3.org/TR/2002/REC-xhtml1-20020801/DTD/xhtml1-strict.dtd scroll down to 'document head'
Adrian Godong
Read my update, I think I found the answer.
Adrian Godong
@Adrian Godong - As in your update, I can't find where `LinkTypes` are defined (it only says "Imported Names"). If it is the same as HTML 4, then `script` is not a defined value.
Oded
A: 

To load a javascript file, you have to write:

<script type="text/javascript" src="/path/to/file.js"></script>

I think you were confused with the CSS file loading:

<link rel="stylesheet" type="text/css" ref="myFile.css"/>
romaintaz
Read up to my comment on Darin's answer. I know how to embed those two files, but that is not the question.
Adrian Godong
A: 

You may go over this http://www.w3.org/TR/html401/struct/links.html#h-12.1.2

nepsdotin
So you're saying a browser should always use HTML 4.01 even though XHTML 1.0 Strict is specified on the doctype declaration?
Adrian Godong
What I gave here is HTML Spec for HTML user, I was in assumption that HTML is being used and this is what mostly used. You may look for similar stuff in XHTML Spec.
nepsdotin
+1  A: 

There is not only a "script" value, "rel" can contain any valid attribute content. The questions are:

  1. Which values have meanings defined (usually via specifications like XHTML 1.0)?
  2. Which browsers support those?

Obviously, the W3C wanted scripts to be includable like stylesheets (<link rel="Stylesheets" …>), but did not mention it in the prosa sections of the spec, only in the DTD comments. You find it in the HTML 4.01 strict DTD as well (XHTML 1.0 is just a reformulation of HTML 4.01 in XML). Strangely, it is neither not mentioned in the corresponding link type section nor in the script section. It could be an artifact of an idea which was rejected later.

This brings us to the answer to question 2. It is not properly implemented in browsers, at least in Safari (you mentioned it yourself). Therefore, you should not use it, because it will not work cross-browser. You can use it as a hack (to include scripts which will not be loaded by Safari), but this is not safe, because you cannot tell if a later version of Safari changes the behaviour.

GodsBoss
Thanks, useful notes.
Adrian Godong