There are different ways: the two most obvious:
- Create a tool like YUI that builds an individual, unique version based on the components you marked as needed so that you can still serve the file as static. MooTools and jQuery UI provide developers with such packages when you download their package to provide you with the most simplified and efficient library possible. I am sure that there is a common universal tool.
- Create a simple Perl / PHP / Python / Ruby script that will contain a bunch of request-based JavaScript files. So, "onerequest.js? Load = ui & load = effects" will go to a PHP script that loads into files and serves them with the correct content type. There are many examples of this, but I personally am not a fan.
I prefer not to serve static files through any kind of script, but I also like to develop my code with 10 or so separate files of a small class without the cost of 10 HTTP requests. Therefore, I came up with my own build process, which combines all the most common classes and functions, and then reduces them to a single file, for example project.min.js, and has a condition in all my views / templates that include this file in production.
Change The "custom build process" is actually an extremely simple perl script. It reads in each of the files that I passed as arguments, and writes them to a new file, optionally passing the whole thing through JSMIN (available in all your favorite languages) automatically.
In a team, what it looks like:
perl build-project-master.pl core.js class1.js etc.js /path/to/live/js/file.js
David mclaughlin
source share