473,396 Members | 1,866 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

JavaScript File Organization

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.
Feb 16 '08 #1
4 2053
On Feb 16, 7:36 pm, SLR <Sean.Rab...@gmail.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.
Feb 16 '08 #2
Paul Wilkins wrote on 16 feb 2008 in comp.lang.javascript:
On Feb 16, 7:36 pm, SLR <Sean.Rab...@gmail.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)
Feb 16 '08 #3
SLR
Thanks for the advice.
Feb 17 '08 #4
SLR wrote on 17 feb 2008 in comp.lang.javascript:
Thanks for the advice.
What advice?

[please always quote on usenet]

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Feb 17 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: Charlene Russ | last post by:
Learn on-line at your own convenience in a user-centered format with plenty of interaction and personal attention. This is a basic level coursed designed to introduce the novice to intermediate...
1
by: Bern | last post by:
which is the organization that decides JavaScript standards?
3
by: happy | last post by:
/* Book name : The prodessional programmers guide to C File name : E:\programs\tc\iti01\ch09\main\01setupm.c Program discription: file setuping -up -Version 01-ver01-W Logic ...
2
by: techfuzz | last post by:
I scoured this group and others looking for the best way to disable a button after the first click to prevent multiple submissions, but never did find anything that worked like they said it would. ...
0
by: rascal_mon | last post by:
I'm new with XML. Please give me some advice. I wonder there are any difference between XML that is automatically generated from ADO and XML file that shows in many textbooks. I found that the...
0
by: Daniel | last post by:
I wrote a pretty neat website today that can utilize no postback AJAXIAN type features. Basically to populate a drop down with a web service call that hits a SQL server, based off the change of...
41
by: Chris Lasher | last post by:
A friend of mine with a programming background in Java and Perl places each class in its own separate file in . I informed him that keeping all related classes together in a single file is more in...
6
by: vinod | last post by:
Hi, The application we have developed uses JavaScript extensively. One of the users of the application is facing a problem. Instead of being hidden, the javascript code in the HTML is displayed or...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.