JavaScript File Organization

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • SLR

    JavaScript File Organization

    I've been using JavaScript for quite some time now, and I've seen
    several techniques regarding file organization. This is the last
    technique I used on my last project:

    I created a "JS directory" for external JS files. I then created one
    global JS file for generic code that linked that all the web-pages
    imported. For any JavaScript code that was specific to a page, I just
    created a separate external JS file in the js directory for that page.

    To sum it up: 1 external JS file for each web-page, and one global JS
    file for all the web-pages.

    Now, I got away with this only because the project that I was working
    on had very few web-pages (i.e. less than 10 pages); however, even
    with this small amount of pages, it started to become a nightmare
    finding what I wanted; I can only imagine how ineffective this would
    become if the project had 20, 30, or even 100+ pages.

    I was hoping that some of you more "experience d" with JavaScript can
    shed some light on this subject.
  • Paul Wilkins

    #2
    Re: JavaScript File Organization

    On Feb 16, 7:36 pm, SLR <Sean.Rab...@gm ail.comwrote:
    To sum it up: 1 external JS file for each web-page, and one global JS
    file for all the web-pages.
    The global file makes good sense, but what on earth would warrant
    having a separate js file for each Web page?
    Placing script code in external files is not a mandatory requirement.
    If multiple pages have script code that is unique to that page, it
    should be kept with that page.

    Comment

    • Evertjan.

      #3
      Re: JavaScript File Organization

      Paul Wilkins wrote on 16 feb 2008 in comp.lang.javas cript:
      On Feb 16, 7:36 pm, SLR <Sean.Rab...@gm ail.comwrote:
      >To sum it up: 1 external JS file for each web-page, and one global JS
      >file for all the web-pages.
      The global file makes good sense, but what on earth would warrant
      having a separate js file for each Web page?
      Placing script code in external files is not a mandatory requirement.
      If multiple pages have script code that is unique to that page, it
      should be kept with that page.
      Indeed, and if you have a huge job, use serverside includes to
      include clientside js that you want to be seperate or that share a few
      pages.

      Debugging of a view source will be so much easier.


      --
      Evertjan.
      The Netherlands.
      (Please change the x'es to dots in my emailaddress)

      Comment

      • SLR

        #4
        Re: JavaScript File Organization

        Thanks for the advice.

        Comment

        • Evertjan.

          #5
          Re: JavaScript File Organization

          SLR wrote on 17 feb 2008 in comp.lang.javas cript:
          Thanks for the advice.
          What advice?

          [please always quote on usenet]



          --
          Evertjan.
          The Netherlands.
          (Please change the x'es to dots in my emailaddress)

          Comment

          Working...