What's the difference between using link and script tag to reference JavaScript source?

link tag is used to relate stylesheets or any other linked documents instead of including javascript files.

The HTML Link Element <link> specifies relationships between the current document and other documents. Possible uses for this element include defining a relational framework for navigation and linking the document to a style sheet.

rel Attribute:

This attribute names a relationship of the linked document to the current document. The attribute must be a space-separated list of the link types values. The most common use of this attribute is to specify a link to an external style sheet: the rel attribute is set to stylesheet, and the href attribute is set to the URL of an external style sheet to format the page. WebTV also supports the use of the value next for rel to preload the next page in a document series.

Possible Values:

  • alternate - An alternate version of the document (i.e. print page, translated or mirror)

  • stylesheet - An external style sheet for the document

  • start - The first document in a selection

  • next - The next document in a selection

  • prev - The previous document in a selection

  • contents - A table of contents for the document

  • index - An index for the document

  • glossary - A glossary (explanation) of words used in the document

  • copyright - A document containing copyright information

  • chapter - A chapter of the document

  • section - A section of the document

  • subsection - A subsection of the document

  • appendix An appendix for the document

  • help A help document

  • bookmark A related document

  • shortcut icon A related (favorite icon) image of the document

While The HTML Script Element <script> is used to embed or reference an executable script within an HTML or XHTML document.


The second (using link) shouldn't work or run and is non-standard.

http://jsfiddle.net/qMKUv/

Tags:

Javascript