Open repository brings modularity to JavaScript

It’s early days, but a group of Perl hackers have banded together to form JSAN, The JavaScript Archive Network. Like the venerable Perl equivalent, CPAN, and other sites that borrowed inspiration (e.g. PEAR for PHP), JSAN aims to be an open repository for JavaScript scripts that are designed in a modular fashion so as to have manageable dependencies that encourage code reuse.

In practical terms, what this means is you can choose a particular module that provides functionality you’d like on your site, and the JSAN system will automatically download and install not only the files for that module, but also the files of any modules upon which that module depends. With the files installed in your site’s directory structure, you can then go ahead and use the functionality they provide in your own scripts.

As JSAN was conceived by Perl hackers, the automated system for downloading and installing JSAN modules is naturally written in Perl. If you’re a developer who works on a Windows box, I sympathise with that groan you just let out. If it’s any consolation, there are rumblings of an “alternative JSAN client” in the works, so fingers crossed. In the meantime, you need to install Perl and get familiar with your operating system’s command prompt before you can install and use JSAN.

Documentation is early-to-nonexistent at this stage, however anyone with some familiarity with CPAN or PEAR and a strong grasp of JavaScript should be able to figure it out based on the nascent installation guide that does exist. Documentation for using individual modules once installed is provided within the script files themselves in a standard format used on CPAN.

Aside from dependency tracking and auto-installation of scripts, JSAN places very few constraints on how scripts should be written. In fact, standalone modules can be obtained easily by browsing to the appropriate script file on the site and downloading it directly–no Perl client required. The initial library of modules, however, clearly favours unobtrustive scripting with JavaScript classes used as namespaces, as presented in DHTML Utopia.

If you do use the official client, you’ll benefit from a standardized directory structure, which will let you use JSAN’s built-in import mechanism for scripts. A trick I first saw in the jsolait library for XML-RPC, the system allows a script to load another script that it requires on-the-fly, instead of requiring the Web developer to load that script with a separate