Samuel Sjöberg's weblog

Skip to navigation

Handling large JS files

My current project contains a rather large portion of javascript. Especially the administration that has a whole bunch of objects/functions to make it smooth to use.

My goal has been to keep the functions in one file, named admin.js, just to make it obvious what it is and also make to make the editing a little easier. However, editing became a pain as the file kept growing. What to do? Split it up of course.

But wait! My initial idea of using only one script then? The reasons for using one file are 1) to have version control on each separate object instead of the file and 2) to only have one nice library to include.

Of to work then. The solution is fairly simple if jump into the terminal and make us a shell script. But first the files needs to be organized. I extracted each function to a separate file and stored it in ./admin/, which is a sub-directory of the directory that originally held the admin.js file. Our script looks like this:

rm -f ./admin.js
cat ./admin/*.js < ./admin.js

This first deletes the admin.js file (if found) and then outputs all javascript files in the admin directory to admin.js.

So, if you are making a library, such as Prototype, and want to impose version control on each function/object instead of the whole library - this is a possible solution!

Pages linking to this entry

Pingback is enabled on all archived entries. Read more about pingback in the Pingback 1.0 Specification.

About this post

Created 5th January 2006 22:11 CET. Filed under Javascript and DOM, Mac OS X.

0 Pingbacks