mainameiz
mainameiz

Reputation: 41

Rails. Large vendor.js?

I have vendor.js file in my rails project containing several vendor libraries altogether and after adding some new libraries I'm facing into this problem in development environment

Started GET "/assets/vendor.js" for 10.40.129.65 at 2013-03-03 14:01:24 +0400
Cache write: 0d6281da1957dd9c5e063fb636c50bd260dae5e2
Cache read: 0d6281da1957dd9c5e063fb636c50bd260dae5e2
Cache read: http://work:3000/assets/vendor.js?
Cache write: http://work:3000/assets/vendor.js?
!! Rack application returned nil body. Probably you wanted it to be an empty string?
!! Unexpected error while processing request: undefined method `each' for nil:NilClass

Trying to remove some libraries fixes the issue and precompiled assets works fine. But I want to make it work in development. Help me please.

vendor.js:

//= require ./vendor/ext/stacktrace.js
//= require jquery
//= require jquery_ujs
//= require underscore
//= require backbone
//= require twitter/bootstrap
//= require js_notifier
//= require ./vendor/ext/mustache-1.4.2
//= require ./vendor/ext/strftime
//= require ./vendor/ext/moment
//= require ./vendor/ext/langs.js
//= require ./vendor/ext/jquery.jgrowl_minimized.js
//= require ./vendor/ext/jquery-ui-1.10.0.custom.min.js
//= require ./vendor/ext/jquery-ui-sliderAccess.js
//= require ./vendor/ext/jquery-ui-timepicker-addon.js
//= require ./vendor/ext/backbone.paginator.js
//= require ./vendor/ext/jquery-deparam.min.js
//= require ./vendor/ext/select2.js
//= require_tree ./templates
//= require ./vendor/channels.js.coffee
//= require ./vendor/ext/bootstrap.switch.js
//= require ./vendor/ext/private_pub
//= require ./vendor/ext/spin.js
//= require ./vendor/ext/jquery.spin.js

I'm using Memcached + Dalli

UPD: I've set cache_store in every environment explicitly (developemnt.rb, production.rb and test.rb) and this fixed the issue until I opened Google Chrome for which the issue raised again. As a result, in FF everything works fine and Chrome fails to load vendor.js (the same server instance (thin) and in the same time for both browsers)

log for ff request:

Cache read: http://work:3000/assets/vendor.js?
Cache read: 577d6ed0d98975b583329c312bd25667620f2497

log for chrome request (same as above):

Started GET "/assets/vendor.js" for 10.40.129.65 at 2013-03-03 20:37:11 +0400
Cache write: 577d6ed0d98975b583329c312bd25667620f2497
Cache read: 577d6ed0d98975b583329c312bd25667620f2497
Cache read: http://work:3000/assets/vendor.js?
Cache write: http://work:3000/assets/vendor.js?
!! Rack application returned nil body. Probably you wanted it to be an empty string?
!! Unexpected error while processing request: undefined method `each' for nil:NilClass

Upvotes: 0

Views: 349

Answers (1)

R Milushev
R Milushev

Reputation: 4315

You may consider to apply index.js technique , as described in this Rails guide (2.1.2). Try to split your big file and include the parts in a manifest file , for example:

In your /app/vendor/assets/javascripts you create a new directory my_libraries and place parts in it . Then in the same directory you create index.js manifest file and include files as normal:

//= require file1
//= require file2

and in your application.js :

//= require my_libraries

EDIT: One solution would be : in your /vendor/ext (the correct path is app/vendor/assets/javascripts/ext, if you have a path like /vendor/ext it will not be clear it is meant to be managed as asset dir , and also it will not be clear what asset you include - js or css) to create index.js with content:

//= require_tree .

and in application.js :

//= require ext

and then you should remove all the references to vendor dir from your application.js manifest . Another mistake is including files in your manifest with .js prefix. In the manifest file you should state inclusions without prefix.

Take a look at the asset-pipeline's documentation explaining the require_tree usage.

Upvotes: 1

Related Questions