Rails 3.1资产管道-公共/资产中缺少文件-为什么这不是默认设置? [英] Rails 3.1 asset pipeline - missing files from public/assets - why isn't this the default?

查看:29
本文介绍了Rails 3.1资产管道-公共/资产中缺少文件-为什么这不是默认设置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

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

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.

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

We needed to change the following configuration value as follows:

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

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

Question: why isn't this the default?

我曾希望将不需要作为清单文件处理的所有内容复制到公共/资产中.我在资产管道上阅读的大部分内容基本上是将资产粘贴在应用程序/资产中,配置清单文件,它应该可以正常工作".由于assess:precompile任务没有吐出任何有关其操作的信息,因此花了一段时间才确定它没有查看我们认为会的文件.

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?

谢谢!

推荐答案

这个想法是让您所有的JavaScript和CSS总是一口气加载,而不是在移动过程中一点一滴地加载.这样一来,您始终可以加载并准备使用世界",而不必到处都包含一堆单独的文件.

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.因此,由于所有内容都已缓存并可以在第一个请求后准备就绪,因此该网站的感知速度应该会加快.

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.

这是一个有争议的决定,因为它包含了Rails,但默认情况下也包含了CoffeeScript.这样,Rails一直是一个自以为是的框架.

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 3.1资产管道-公共/资产中缺少文件-为什么这不是默认设置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆