ruby-on-rails-3.1 – 资产管道不压缩javascript到application.js

我有两个问题.

>我错误地假设我的所有JavaScript应该被压缩到application.js认情况下在rails 3.1甚至在开发模式?
>如果没有,那么为什么我的标签有我所有的30个我的javascripts,并承担加载?

我的application.js文件如下所示:

//= require jquery
//= require jquery_ujs
//= require jquery-ui
//= require_tree .

在浏览器中,它被渲染为:

// This is a manifest file that'll be compiled into including all the files listed below.
// Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
// be included in the compiled file accessible from http://example.com/assets/application.js
// It's not advisable to add code directly here,but if you do,it'll appear at the bottom of the
// the compiled file. 
//
;

虽然我所有的其他javascript都被渲染了.

谢谢一堆!

解决方法

如果这是一个新的Rails应用程序调试模式认是打开的.调试模式告诉Sprockets将每个文件标签写入HTML源代码.这样做是为了方便源文件调试.

如果你想在开发模式中只有一个文件去你的development.rb并设置:

config.assets.debug = false

这将为每个清单提供一个文件.

压缩认情况下不进行开发,但是如果您也希望这样做,则设置:

config.assets.compress = true

并且您将需要将压缩器选项从production.rb移动到application.rb,以便开发环境可访问它们.

我在开发模式下调试,但我不使用压缩,因为处理文件需要额外的时间.

相关文章

validates:conclusion,:presence=>true,:inclusion=>{...
一、redis集群搭建redis3.0以前,提供了Sentinel工具来监控各...
分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣...
上一篇博文 ruby传参之引用类型 里边定义了一个方法名 mo...
一编程与编程语言 什么是编程语言? 能够被计算机所识别的表...
Ruby类和对象Ruby是一种完美的面向对象编程语言。面向对象编...