SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Sep 2006
    Posts
    50
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    javascript and external sheets

    Does placing javascript on an external style sheet, actually speed up a site, in the same way as placing css on an external style sheet

    Thanks in advance

  2. #2
    SitePoint Zealot milenko1054's Avatar
    Join Date
    Jan 2004
    Location
    Ohio
    Posts
    113
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Short answer - yes.

    Long answer - yes, assuming the external css/javascript files are being cached by the user's browser. Using external javascript files will take advantage of the cache and load style sheets/javascript files from the user's local machine instead of continuously re-requesting them from your web server.

    This will make your page load faster as accessing a file from the cache is much faster than requesting and loading the same file from a web server.


  3. #3
    SitePoint Enthusiast
    Join Date
    Sep 2006
    Posts
    50
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi there,

    Thanks for the answers !Much appreciated.

    How do I create the javascript in an external page and then call them or do you know of a tutorial

    Is it done exactly the same way as CSS - where you simply creat link rel tag and link it to the external sheet.

    Also, how is the external sheet saved - as .js

    Are there any possible problems that I might experience ?

    Thanks
    Last edited by richardf; Sep 11, 2006 at 12:43.

  4. #4
    SitePoint Zealot milenko1054's Avatar
    Join Date
    Jan 2004
    Location
    Ohio
    Posts
    113
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just write your scripts as normal and save them in a file with the extension .js

    Then refrence that file in the <head> of your html file like so:
    <script type="text/javascript" src="yourfile.js"></script>

    When referencing an external javascript file like this, the javascript is actually transparently encoded in the html so the end result is the same as if you wrote the javascript directly in the <head>. The benefit is in the caching behavior - the javascript part of your html file can be loaded from the user's local machine and doesn't have to come from your server on every page load.

    So, just write the javascript functions in the external file, save it with a .js extension, include the <script> reference in the <head> of your html document and call the functions normally.


  5. #5
    SitePoint Enthusiast
    Join Date
    Dec 2005
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thanks

    Thanks Milenko, That was very helpful.

    Cheers


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
  •