Jammit 压缩在开发模式下工作,但不能像压缩 JS 那样工作
我的 Rails 应用程序现在已经相当进步了,我想正确压缩包含的 JS 文件(带插件的 Aloha 编辑器 + Gritter,用超过 1MB 的 JS 组成多个文件)。我决定使用 Jammit,因为它与 Rails 集成良好。这是我的 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
解释一下:aloha.js 是一个扩展的 jQuery 1.4.2 lib,/javascripts/.js 和 /gritter/.js 中的文件主要依赖于它(jQuery)。 我直接将标签包含在我的视图代码中
<%= include_javascripts :admin %>
。
当切换到开发模式时(assets.yml 有 package_assets: on),Jammit 单独保留 JS 文件并一一嵌入所有文件,我的应用程序就很好。
然而,在生产模式下(env = :development,或者assets.yml有package_assets:always),Jammit会创建一个大约700kB的压缩JS文件(哇,那是一个胖怪物),它可以正确嵌入,但我收到一个JS错误“ jQuery 未定义”页面加载时。我的第一个猜测是,JS 文件的顺序在编译过程中发生了变化,尽管它不应该发生变化?
还有一件事:将压缩器保留为默认值 (yui) 会导致加载时出现更严重的 JS 错误。
有人可以帮我吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我们在使用执行“高级优化”的编译器压缩 Aloha Editor 时遇到了很多问题 - aloha 核心编译良好,但 ExtJS 依赖项编译失败。
由于
aloha.js
已经编译完毕,看看是否可以跳过编译,直接连接到结果文件,而不是再次编译。另一件要尝试的事情是看看您是否可以在编译器或
basic_optimizes
中仅启用whitespace_only
选项。这将显示是否是编译过程的问题。We've had a lot of issues compressing Aloha Editor with compilers that do "advanced optimisations" - aloha core compiles fine, but the ExtJS dependency fails the compile.
As
aloha.js
is already compiled, see if it can skip compilation and just be concatenated to the result file instead of compiled again.Another thing to try is see if you can enable just the
whitespace_only
option in your compiler orbasic_optimisations
. This will show whether or not it is an issue with the compilation process or not.文件的顺序可能是问题所在。我建议明确指定每个文件并按照您想要的顺序(即不要执行 /*.js)。
如果这对您有用,那么您可以将一些不需要订单的 javascript 文件移动到子文件夹中,并在该子文件夹上调用 /*.js。
The order of the files is likely the issue. I would recommend specify each file explicitly and in the order you want them in (ie. do not do /*.js).
If this works for you, then you could move some of the javascript files that don't require an order into subfolders and call /*.js on that subfolder.