My Rails app is fairly progressed now, and I want to compress the included JS files (Aloha Editor with plugins + Gritter, making up multiple files with over 1MB of JS) properly. I have decided for Jammit, because of its fine Rails integration. Here is my config/assets.yml:
package_assets: always
javascript_compressor: closure
compressor_options:
compilation_level: ADVANCED_OPTIMIZATIONS
javascripts:
admin:
- public/aloha/aloha.js
- public/aloha/plugins/com.gentics.aloha.plugins.Format/plugin.js
- public/aloha/plugins/com.gentics.aloha.plugins.Table/plugin.js
- public/aloha/plugins/com.gentics.aloha.plugins.List/plugin.js
- public/aloha/plugins/com.gentics.aloha.plugins.Link/plugin.js
- public/javascripts/*.js
- public/javascripts/gritter/*.js
For explanation: aloha.js is an extended jQuery 1.4.2 lib, and the files in /javascripts/.js and /gritter/.js are mostly dependent on it (jQuery). I am including the tags in my view code with
<%= include_javascripts :admin %>
straightforward.
When switched to dev mode (assets.yml has package_assets: on), Jammit leaves the JS files alone and embeds all of them, one by one, and my app is just fine.
However, when in production mode (env = :production, or assets.yml has package_assets: always), Jammit creates a compressed JS file of roughly 700kB (wow, that's a fat monster) which embeds correctly, but I get a JS error "jQuery is not defined" on page load. My first guess would be that the order of JS files is changed during compilation, even though it should not?
One more thing: Leaving the compressor at default (yui) causes even worse JS errors on loading.
Can someone help me, please?