1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

getting javascripts into external file

Discussion in 'JavaScript' started by makemoneyfromgoogle, Mar 8, 2010.

  1. #1
    I am attempting to get most of the javascripts in the html of my site into external files (ina directory on my site). The process seems fairly straigtfoward when there is a single script in the head or body - you just create a script with a url path leading to the external file (a page with the actual script with a .js extention).

    But some of my scripts have a section in the head section, and then a corresponding section in the body snippet. I'm not sure exactly how it works, but it seems like the script snippet in the body section somehow calls the script in the head section. I was wondering if anyone had any suggestions as to how to get these type of javascripts into external file?

    Do I just create a external file for the javascript section in the head, or do I do this just for the section in the body, or... can I create external files for both of the scripts locinted in the head and body? Thanks for any suggestions.

    mohamed elgharib
    SEMrush
     
    makemoneyfromgoogle, Mar 8, 2010 IP
    SEMrush
  2. twistedspikes

    twistedspikes Notable Member

    Messages:
    5,694
    Likes Received:
    293
    Best Answers:
    0
    Trophy Points:
    230
    #2
    Some scripts are best not in their own file.

    If a script is calling a function that has been defined in the head section's JS then it's probably best just to leave that script as is and not put it in it's own file.
     
    twistedspikes, Mar 8, 2010 IP
  3. www.petermoss.com

    www.petermoss.com Guest

    Messages:
    21
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    You can call Javascript in head or body, normally you put your generic code in an external file, you know, the stuff that does not reference any particular document elements. Say you want to have a script that will be reused in many pages, that should go to the external file and be called from the head section.

    It is always good to put stuff in external files, it is easier to read the HTML code, but it involves another GET request on the browser if you care about that sort of thing.
     
    www.petermoss.com, Mar 9, 2010 IP