SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict
    Join Date
    Aug 2007
    Posts
    328
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How can you import multiple javascript files

    Hi,
    I'm just getting started with javascript and am trying to learn to use jquery.
    What's becomming appartent to me is that whenever I create something new and want to put it in it's own file I'll have to reference it in the head of each page.

    Eventually this will probably become a long list and look quite ugly, is there a way for me to create a javascript file called abc.js for example, and within that file have a link to all of my other javascript files that I want to use.

    This way there would only be 1 javascript link in my actual markup.

    What I'm getting it is like the javascript equivalent of css import (Though I've never really played with that either )

    Is it possible?

    regards
    steve

  2. #2
    SitePoint Addict joaquin_win's Avatar
    Join Date
    Jul 2005
    Location
    Venezuela
    Posts
    224
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here's a PHP option to do that: http://www.ejeliot.com/blog/72

  3. #3
    SitePoint Evangelist elgumbo's Avatar
    Join Date
    Nov 2002
    Location
    North West, UK
    Posts
    545
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can just have one file with all your javascript functions in it. Most people do this and just call it ..er.. functions.js . You can then just link to this one file in the head of the html .

    Don't use any <script> tags in the functions.js file though.

  4. #4
    SitePoint Addict
    Join Date
    Aug 2007
    Posts
    328
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thansk for the link joaquin, I'll check that out.

    I know I could put all of my functions into a single file, but then it becomes less modular.
    If for example, I want to change a function slightly, I'll have to dig around in that one file, to find it, or edit the original and re-combine them again.

    I suppose it's good for a website that wont need to change it's javascript very often, but as I'm in the early stages of javascript, it's not ideal for me, I suppose then I should settle for ugly markup in the header then lol or go the php route as previously mentioned.

    So in short, you can't import javascript like you can css.

    thanks for your answers

  5. #5
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    Many sites have a production process where the modular development files are packaged together into the one file for deployment.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


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
  •