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.

Which one is best? JS as inline code or as an external file.

Discussion in 'JavaScript' started by ready2work, Jul 26, 2007.

  1. #1
    Which is the best place to have Javascript? Should we write the code using the script tag within head tag itself or Is it best to have it in an external file? I heard that the search engine crawlers prefer external files? Is that so?
     
    If someone posts a solution, use the "Best Answer" link in their post to pick it as the best answer.
    ready2work, Jul 26, 2007 IP
  2. samyak_bhuta

    samyak_bhuta Peon

    Messages:
    19
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Hi R2W,

    I recommend you to have it in seperate file. Since doing it increases "compartmentalization" of code. It will bring following benifit to you.

    • You can use your javascript (or some functions of it) in other pages. On the contraray, if you have same code at multiple places keeping them all in sync, as they change and grow, will become nighmare. It's better to have them seperate right from the begining.
    • When distribution of work is between designer and programmer both can work independently. It helps in versioning also.

    Infact, I would encourage you to have different javascript files for different purposes. That way it will be easy to manage you code while it is chaning and growing and growing and changing :).

    Remember to divide and rule !!!

    Hope this will help.

    Regards,

    Samyak