Is this a silly question?

Discussion in 'JavaScript' started by oo7ml, Feb 6, 2008.

  1. #1
    I have just noticed that alot of my pages have chunks of javascript all over them.

    Can i cut this JS and save it as an external file.js

    then put

    <script language="JavaScript" type="text/javascript" src="js/file.js"></script>

    in the <head> of each page


    It seems to work but is it ok to do this?

    Sorry if this seems a very silly question? thanks in advance
     
    oo7ml, Feb 6, 2008 IP
  2. ToddMicheau

    ToddMicheau Active Member

    Messages:
    183
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    58
    #2
    If everything is executing fine then putting your javascript in an external file is perfectly alright. You might even be able to combine all your files into one file to save on html code. Really the only reason for doing this is to tidy up your html code, at least in my opinion, that and it's alot easier to edit if a function starts going all funny shaped- no need to scroll through all the html to find the block of javascript that is messing up. . .
     
    ToddMicheau, Feb 6, 2008 IP
  3. oo7ml

    oo7ml Well-Known Member

    Messages:
    656
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    105
    #3
    Ok cool, thanks, yeah it alot cleaner this way, thanks
     
    oo7ml, Feb 6, 2008 IP
  4. WebHostingNerds.com

    WebHostingNerds.com Peon

    Messages:
    59
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    you can do it with the part of javascript where you define functions etc so you'll just have javascript calls in your HTML code
     
    WebHostingNerds.com, Feb 6, 2008 IP