轨。大vendor.js?

时间:2013-03-03 10:12:40

标签: ruby-on-rails caching asset-pipeline assets

我的rails项目中有vendor.js文件,其中包含几个供应商库,在添加了一些新库后,我在开发环境中面临这个问题

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

尝试删除某些库可以解决问题并且预编译资产可以正常工作。但我想让它在开发中发挥作用。请帮帮我。

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

我正在使用Memcached + Dalli

UPD: 我已经明确地在每个环境中设置了cache_store(developemnt.rb,production.rb和test.rb),这解决了这个问题,直到我打开谷歌Chrome再次引发了这个问题。因此,在FF中一切正常,Chrome无法加载vendor.js(同一服务器实例(瘦),同时适用于两个浏览器)

记录ff请求:

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

记录chrome请求(与上面相同):

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

1 个答案:

答案 0 :(得分:1)

您可以考虑应用index.js技术,如this Rails guide(2.1.2)中所述。尝试拆分大文件并将这些部分包含在清单文件中,例如:

/app/vendor/assets/javascripts中,您可以创建一个新目录my_libraries并在其中放置部分内容。然后在同一目录中创建index.js清单文件并按正常方式包含文件:

//= require file1
//= require file2

和您的application.js

//= require my_libraries

编辑:一个解决方案是:在您的/vendor/ext中(正确的路径为app/vendor/assets/javascripts/ext,如果您有/vendor/ext这样的路径,则不清楚它是否需要管理作为资产目录,并且还不清楚您包含的资产(js或css)与内容创建index.js

//= require_tree .

application.js

//= require ext

然后您应该从vendor清单中删除对application.js目录的所有引用。另一个错误是在清单中包含.js前缀的文件。在清单文件中,您应该说明没有前缀的包含。

查看资产管道的文档,解释require_tree用法。