link rel="script" usage

19,338

Solution 1

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.

Solution 2

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.

Solution 3

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"/>
Share:
19,338
Adrian Godong
Author by

Adrian Godong

Updated on June 19, 2022

Comments

  • Adrian Godong
    Adrian Godong almost 2 years

    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.