Rails 3.1资产管道 - 从公共/资产中丢失文件 - 为什么这不是默认值?

时间:2022-09-11 00:13:41

After I deployed my upgraded Rails 2.3.x -> 3.1 (rc4) app to our test environment this afternoon, all of our stylesheets and JavaScript files were returning 404 errors. We had added the rake assets:precompile task to our post-deploy script and it took a while to determine why the assets folder didn't have the pre-compiled files we expected.

在今天下午将我升级的Rails 2.3.x - > 3.1(rc4)应用程序部署到我们的测试环境后,我们所有的样式表和JavaScript文件都返回了404错误。我们已经将rake资产:预编译任务添加到我们的部署后脚本中,并且需要一段时间来确定资产文件夹为什么没有我们预期的预编译文件。

In the end, the files weren't being compiled because apparently only application.css and application.js (+ non JS/CSS files) are processed by default.

最后,文件没有被编译,因为默认情况下只处理application.css和application.js(+非JS / CSS文件)。

We needed to change the following configuration value as follows:

我们需要更改以下配置值,如下所示:

config.assets.precompile += %w( *.js *.css )

Question: why isn't this the default?

问题:为什么这不是默认值?

I would have expected that anything that wasn't necessary to process as a manifest file would just get copied into public/assets. Much of what I've read on the asset pipeline is essentially "stick your assets in app/assets, configure the manifest files, and it should just work". Since the assets:precompile task didn't spit out any information about what it was doing, it took a while to determine that it just wasn't looking at the files we thought it would.

我原本预计,任何不必作为清单文件处理的东西都会被复制到公共/资产中。我在资产管道上阅读的大部分内容基本上是“将您的资产放在应用程序/资产中,配置清单文件,它应该正常工作”。由于资产:预编译任务没有吐出任何有关它正在做什么的信息,因此需要一段时间才能确定它只是没有查看我们认为会存在的文件。

Is there any reason why this would not be a good value for the precompile configuration?

有什么理由说这对于预编译配置来说不是一个好的价值?

Thanks!

2 个解决方案

#1


9  

The idea is to have all your JavaScript and CSS always loaded in one shot, rather than loading bits and pieces as you move along. That way you always have the 'world' loaded and ready to work with, rather than having to include a whole bunch of individual files here and there.

我们的想法是让你的所有JavaScript和CSS总是一次性加载,而不是在你移动时加载点点滴滴。这样你总是可以加载“世界”并准备好使用,而不必在这里和那里包含一大堆单个文件。

It's a bit of a larger 'up front' load, but then the browser should keep loading all the javascript from cache. So the perceived speed of the site should speed up due to having everything cached and ready to go after the first request.

这是一个更大的“前期”负载,但随后浏览器应继续加载缓存中的所有javascript。因此,由于在第一次请求之后缓存了所有内容并准备好了,所以网站的感知速度应该加快。

This was a controversial decision to include for Rails, but so is including CoffeeScript by default. Rails has always been an opinionated framework that way.

这是一个有争议的决定,包括Rails,但默认包括CoffeeScript。 Rails一直是一个固执己见的框架。

#2


0  

the new sprockets-based pipeline compiles all the files in /asssets/stylesheets and /assets/javascripts get compiled into application.css and application.js, respectively, by default.

新的基于sprockets的管道编译/ asssets / stylesheets中的所有文件,/ assets / javascripts分别编译为application.css和application.js,默认情况下。

In your views, you only need to link the application files, sprockets handles the rest.

在您的视图中,您只需链接应用程序文件,sprockets处理其余文件。

Update: Well, you don't have to make it all into just one file... You could have an shared.js, secure.js and public.js and have them each include the parts they need...

更新:嗯,你不必把它全部变成一个文件...你可以有一个shared.js,secure.js和public.js,并让它们各自包含他们需要的部分......

Think of them not as javascript files, but manifest files that establish groups of javascript files which you can then include as a group with a single javascript_include_tag. While the default is to include everything in the folder into a single file, you can be always pick and choose what to include, and what not.

可以认为它们不是javascript文件,而是构建javascript文件组的清单文件,然后您可以将其作为一个包含单个javascript_include_tag的组包含在内。虽然默认情况下将文件夹中的所有内容都包含在一个文件中,但您可以随时选择要包含的内容,以及不包含的内容。

The 'precompile' task simply runs those manifest files and compiles the multiple files into one, while pre-processing and sass or coffee script it runs across.

“预编译”任务只是运行那些清单文件,并将多个文件编译成一个,同时运行预处理和sass或coffee脚本。

#1


9  

The idea is to have all your JavaScript and CSS always loaded in one shot, rather than loading bits and pieces as you move along. That way you always have the 'world' loaded and ready to work with, rather than having to include a whole bunch of individual files here and there.

我们的想法是让你的所有JavaScript和CSS总是一次性加载,而不是在你移动时加载点点滴滴。这样你总是可以加载“世界”并准备好使用,而不必在这里和那里包含一大堆单个文件。

It's a bit of a larger 'up front' load, but then the browser should keep loading all the javascript from cache. So the perceived speed of the site should speed up due to having everything cached and ready to go after the first request.

这是一个更大的“前期”负载,但随后浏览器应继续加载缓存中的所有javascript。因此,由于在第一次请求之后缓存了所有内容并准备好了,所以网站的感知速度应该加快。

This was a controversial decision to include for Rails, but so is including CoffeeScript by default. Rails has always been an opinionated framework that way.

这是一个有争议的决定,包括Rails,但默认包括CoffeeScript。 Rails一直是一个固执己见的框架。

#2


0  

the new sprockets-based pipeline compiles all the files in /asssets/stylesheets and /assets/javascripts get compiled into application.css and application.js, respectively, by default.

新的基于sprockets的管道编译/ asssets / stylesheets中的所有文件,/ assets / javascripts分别编译为application.css和application.js,默认情况下。

In your views, you only need to link the application files, sprockets handles the rest.

在您的视图中,您只需链接应用程序文件,sprockets处理其余文件。

Update: Well, you don't have to make it all into just one file... You could have an shared.js, secure.js and public.js and have them each include the parts they need...

更新:嗯,你不必把它全部变成一个文件...你可以有一个shared.js,secure.js和public.js,并让它们各自包含他们需要的部分......

Think of them not as javascript files, but manifest files that establish groups of javascript files which you can then include as a group with a single javascript_include_tag. While the default is to include everything in the folder into a single file, you can be always pick and choose what to include, and what not.

可以认为它们不是javascript文件,而是构建javascript文件组的清单文件,然后您可以将其作为一个包含单个javascript_include_tag的组包含在内。虽然默认情况下将文件夹中的所有内容都包含在一个文件中,但您可以随时选择要包含的内容,以及不包含的内容。

The 'precompile' task simply runs those manifest files and compiles the multiple files into one, while pre-processing and sass or coffee script it runs across.

“预编译”任务只是运行那些清单文件,并将多个文件编译成一个,同时运行预处理和sass或coffee脚本。