JavaScript File Organization

S

SLR

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 "experienced" with JavaScript can
shed some light on this subject.
 
P

Paul Wilkins

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.
 
E

Evertjan.

Paul Wilkins wrote on 16 feb 2008 in comp.lang.javascript:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,067
Latest member
HunterTere

Latest Threads

Top