sinisterchipmunk/jax — Issue #34: Omit unused portions of Jax from build
Author: sinisterchipmunk
Created: 2011-12-06 05:24:36+00:00
State: open
Labels: enhancement

Since Jax uses Ruby and Rails on the server and/or precompile side, it has one major advantage that AFAIK no other WebGL framework has: optimizability. And yet, we aren't yet using it.

Case in point: the Utah Teapot. It's one of those meshes that is great for testing and makes a pretty good welcome-to-Jax app, but I don't see it really making an appearance in many production apps. But there it is, consuming a whopping 15% of the precompiled Jax application, even when gzipped!

We need a way to optimize out these potentially-useless code segments. There are a few ways to do this, but none of them strikes me as particularly novel. I'm open to further suggestions. Here's what I'm able to come up with so far:

1. Start explicitly `#= require`ing individual files. This sucks, because not only does it break all existing applications, it forces the developer to have a fairly meaningful understanding of how Jax is organized internally (which changes a lot from release to release, anyway).

2. Add a `#= reject` directive so that users can explicitly reject certain files. This sucks, because it forces the developer to learn "one more thing" before they can deploy to production. Jax is about doing what you want, without you necessarily having to tell it how.

3. Add a line to `config/application.rb` something like `config.jax_exclusions = ['jax/builtin/meshes/teapot.js']`. This sucks for reasons 1 and 2 combined, but it strikes me as the happy medium between the two.

4. Discern which source files are being used by scanning the developer's files for stuff like `new Jax.Mesh.Teapot`, and adapt the Jax sources to match. This sucks because a brute force regexp search on all javascript files strikes me as all of: brittle, un-DRY, and slow (though with Rails' new caching mechanisms and precompiling, speed may be less of an issue). This would likely involve some ERB magic in `jax/application.js` so that the necessary source files could be prepended prior to the Sprockets preprocessors doing their thing. Even with my consternations, this is the approach I'm currently leaning toward. Please, give me a better solution!