简体   繁体   中英

Rails and Javascript minifier and aggregator

I am starting a new rails project and is there any rails plug in I can use that will minify my javascript and combine it into 1 file?

I would imagine there might be a rake task for this.

What would be used for this in rails?

There are several actually:

I've only used asset packager, and its been nothing but a joy.

Also worth reading: http://github.com/blog/551-optimizing-asset-bundling-and-serving-with-rails

Rails has built in javascript file merging.

http://apidock.com/rails/ActionView/Helpers/AssetTagHelper/javascript_include_tag

javascript_include_tag :all, :cache => true

I then use nginx's built in gziping to compress the file size, since it does a pretty good job. There are numerous plugins to do it also:

http://github.com/sbecker/asset_packager/ http://github.com/sstephenson/ruby-yui-compressor/

You might also want want to checkout Juicer . It primarily combines files, but it can work with YUI Compressor and JSLint if you don't mind Java in your toolkit/dependency chain. It's also not specific to Rails, so you could "standardize" on it for all your projects--if you find you like it.

Just an idea.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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