资产管道未将 javascript 压缩到 application.js 中

发布于 2024-12-10 06:50:42 字数 836 浏览 0 评论 0原文

我有两个问题。

  1. 我是否做出了错误的假设,即默认情况下,即使在开发模式下,我的所有 JavaScript 都应该在 Rails 3.1 中压缩到 application.js 中?

  2. 如果没有,那么为什么我的标签包含我的全部 30 个 javascript,并且需要很长时间才能加载?

我的 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 都完整呈现。

谢谢一堆!

I have two questions.

  1. Am I making a wrong assumption that all my javascripts should be compressed into application.js by default in rails 3.1 even in development mode?

  2. If not, then why does my tag have all 30 of my javascripts and take forver to load?

My application.js file looks like this:

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

And in the browser it is rendered as:

// 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. 
//
;

While all my other javascripts are rendered in full.

Thank a bunch!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

漆黑的白昼 2024-12-17 06:50:42

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

如果您只想在开发模式下使用一个文件,请转到development.rb 并设置:


config.assets.debug = false

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

默认情况下,开发时不启用压缩,但如果您也想要,请设置:


config.assets.compress = true

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

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

If this is a new Rails app debug mode is on by default. Debug mode tell Sprockets to write tags for each file into the HTML source. This is done to facilitate source file debugging.

If you want to have just one file in development mode go to your development.rb and set:


config.assets.debug = false

This will give you one file for each manifest.

Compression is NOT on by default for development, but if you wanted that too, then set:


config.assets.compress = true

And you will need to move the compressor options from production.rb to application.rb so they are accessible to the development environment.

I turn debug off in dev mode, but I don't use compression because of the extra time it takes to process the files.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文