Here are some common simple strategies to make those JS packages:
- Traverse the JS directory recursively and put all files into the package
- Mantain a list of JS files per page/site/app and use that to assemple the JS packages
- Include support in the templating system to arrange for the generation of an appropriate JS package
In a recent post to the Joose mailing list, we talked about different strategies to find the ideal packages to minimize load time. My current thinking is that it is very hard to do much better than to load everything (for the whole app / sub-site) at once.
Here are some examples for strategies to determine what to put inside a JS package:
Page A needs JS file 1,2,3,4,5
Page B needs JS file 2,3,4,5,6
In order to minimize http requests, the strategies would be to
1. Visit page A , load a package containing all needed JS files
2. Visit page B, once again load a package containing all needed JS files
- plus: Simple
- minus: Loading too much data
1. Visit page A, load a package containing all needed JS files
2. Visit page B, somehow determine that we were already in Page A and use that package plus and extra request for file 6
- plus: Minimal data
- minus: Very complex, needs support on the server for dynamically assembling JS packages.
1. Visit page A Load a package containing all needed JS files for the entire App
- plus: Simple
- plus: Maximum result from zip-compression
- minus: User loads code which he might not need eventually
If it is possible to easily determine disjunct packages of JS files, it makes of course sense to load these separately. In this case, it is, however, highly likely that we are talking about separate applications anyway.