简体   繁体   English

如何压缩在apache / passenger上运行的Rails应用程序提供的javascript文件?

[英]how to compress javascript files served from my rails app running on apache/passenger?

I'm using Apache 2.2, Passenger 3.0.2, Rails 3. 我正在使用Apache 2.2,Passenger 3.0.2,Rails 3。

I've managed to compress the css file by modifying the deflate.conf file. 我已经通过修改deflate.conf文件来压缩css文件。 However, when I run the firefox addon yslow, it still says the javascript files are uncompressed. 但是,当我运行Firefox附加组件yslow时,它仍然说javascript文件未压缩。

<IfModule mod_deflate.c>
          AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css application/javascript text/javascript application/x-javascript
</IfModule>

Above, I'm using all three variants: "application/javascript text/javascript application/x-javascript" but no luck. 上面,我使用了所有三个变体:“应用程序/ javascript文本/ javascript应用程序/ x-javascript”,但是没有运气。

Here's the message from yslow: 这是来自yslow的消息:

Grade D on Compress components with gzip 使用gzip压缩组件的D级

There are 3 plain text components that should be sent compressed 有3个纯文本组件应压缩后发送

 * http://myhost.dyndns.org:8080/javascripts/jquery-1.4.2.min.js?... * http://myhost.dyndns.org:8080/javascripts/jquery.validate.min.js?... * http://myhost.dyndns.org:8080/javascripts/rails.js?... 

Jammit is an industrial strength asset packaging library for Rails, providing both the CSS and JavaScript concatenation and compression that you'd expect, as well as YUI Compressor and Closure Compiler compatibility, ahead-of-time gzipping, built-in JavaScript template support, and optional Data-URI / MHTML image and font embedding. Jammit是用于Rails的具有工业实力的资产包装库,可提供您期望的CSS和JavaScript串联和压缩,以及YUI Compressor和Closure Compiler兼容性,提前gzip,内置JavaScript模板支持,以及可选的Data-URI / MHTML图像和字体嵌入。

http://documentcloud.github.com/jammit/ http://documentcloud.github.com/jammit/

Assuming that you are using capistrano, add a deployment task that compresses our javascript files in-place on the production server. 假设您使用的是capistrano,请添加一个部署任务,该任务会在生产服务器上就地压缩我们的javascript文件。

Check this: http://blog.jcoglan.com/2007/05/26/make-capistrano-compress-your-javascript-and-css-automatically/ 检查一下: http : //blog.jcoglan.com/2007/05/26/make-capistrano-compress-your-javascript-and-css-automatically/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM