2

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?

4

2 回答 2

2

我们在使用执行“高级优化”的编译器压缩 Aloha 编辑器时遇到了很多问题 - aloha 核心编译得很好,但 ExtJS 依赖项编译失败。

由于aloha.js已经编译,看看它是否可以跳过编译并连接到结果文件而不是再次编译。

要尝试的另一件事是查看是否可以仅whitespace_only在编译器或basic_optimisations. 这将显示它是否是编译过程的问题。

于 2011-03-22T12:29:10.903 回答
0

文件的顺序可能是问题所在。我建议明确指定每个文件并按照您希望它们的顺序(即不要执行 /*.js)。

如果这对您有用,那么您可以将一些不需要订单的 javascript 文件移动到子文件夹中,然后在该子文件夹上调用 /*.js。

于 2011-04-12T09:43:48.290 回答