SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Guru
    Join Date
    Nov 2005
    Location
    Midwest
    Posts
    777
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Difference between LINK and SCRIPT for JavaScript

    Hello

    I have always wondered what the difference was between the 2 below statements. I tried searching Google but I was not able to find anything substantial. Does anyone know if there is a difference, and if so, what is the difference? I included some definitions I found but it does not distinguish the 2 for me.

    <link rel=”javascript” href=”jsFile.js” type=”text/javascript”>

    Link is a general purpose tag for linking media-independent content into a document.
    Link belongs inside the HEAD element.

    <script language="JavaScript" src="jsFile.js" ></script>

    The script element provides a container for lines of script code written in any scripting language that the browser is capable of interpreting.

    Thanks in advance for your time.

  2. #2
    SitePoint Addict
    Join Date
    Dec 2005
    Posts
    262
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There really isn't a difference for the end user, link is a newer standard and is able to link anything, so it replaces both style and script tags.

    However, when you dig a little deeper, the link tag shows the browser there is a relationship between two documents; in this case, the link tags says that the page gets its javascript from some external file, so the browser should load it.

    The script tag just tells the browser that the source of the javascript is some file.

    As an FYI the "language" attribute of the script tag has been deprecated, so instead you should be using type='text/javascript' in the script tag.

  3. #3
    SitePoint Guru
    Join Date
    Nov 2005
    Location
    Midwest
    Posts
    777
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you for the information. One other question… when you are dealing with multiple include files and multiple people updating files, it is possible to accidentally add a reference to the same JavaScript file. Are either the link tag or the script tag smart enough to notice the same JavaScript file is being referenced so it only loads the JavaScript file once (even though there are 2 references)?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •