javascript - Combining many JS files with Rails Asset Pipeline -


i making long-overdue upgrade rails 3.0.20 rails 3.1.10. (later i'll upgrade 3.2, want more major changes in 3.1 working codebase first. don't have test suite, please bear me overcome quite bit of technical debt. thankfully, app isn't large or complex.)

i've had separate js files various views in app. now, asset pipeline wants combine of 1 file. problem is, lot of variables , function names collide , cause problems.

my assumption need use kind of namespacing here, , initialize code in particular namespace on page needs it.

is there standard way this? or, there better way overall?

one note of clarification: i'm not ready switch coffeescript yet.

the keystone of asset pipeline manifest file. default rails creates 1 javascript files at

app/assets/javascripts/application.js 

this manifest uses directives declare dependencies in asset source files. 1 of these directives is

require_tree 

which works require directory, operates recursively requiring files in subdirectories. in rails application generated application.js contained

//= require_tree . 

which requires files inside javascript asset folder. removing it, not javascript files combined 1 anymore. have require javascript files per view. answered in question javascript file per view in rails.


having said that, please reconsider plan. after rails not annoy you, purpose. reasons of efficiency should have few http requests possible. if javascript code gets loaded upfront might have better performance, instance due caching.


Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -