In Ruby on Rails, is it possible to concatenate multiple Javascript files at runtime?

I am building a Facebook app that relies heavily on Javascript. I have some Javascript files for this. Since in Facebook development, the page is processed through a tunnel, excess latency is added when multiple javascript files are requested. Is it possible to combine the contents of multiple javascript files at runtime? Having multiple files makes development easier and therefore I avoid combining it at design time.

+1


source to share


5 answers


Better than combining at runtime, have a look at Frizione . It is an environment that will allow you to concatenate javascript files during deployment and compress them. This way you can save everyone around you. It also generates document generation and JSLint validation, but that's just an added bonus.



+1


source


You can pass a :cache

parameter javascript_include_tag

that will combine the files into one:

<%= javascript_include_tag :all, :cache => true %>

      



Note that this depends on what is ActionController::Base.perform_caching

set to true, which is the default for the Rails runtime.

+14


source


in your config file for the environment located /config/environments

at you have a file for each, for example development.rb

etc.

In this file, you can set config.assets.debug = false

and this will reduce the files to 1 js file and 1 css file.

+6


source


Gemmit caught it well too, to combine js and css files.

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

+1


source


I have used the asset_packager gem to do this in my applications.

It will combine and minify your javascript (and CSS) files for production and add some view helpers that make it very easy to use. There's a rake command that you run to generate zipped files if the originals have changed.

0


source







All Articles