Heroku 上更新到 Rails 3.1 时的资产管道

发布于 2024-12-02 13:47:12 字数 1021 浏览 1 评论 0原文

我刚刚将 Heroku 上的应用程序从 Rails 3.0 升级到 3.1,并且正在尝试使资产管道正常工作。主要问题是,对于每个资产,我可以从 heroku 日志中读取以下类型的行:

2011-09-03T16:35:28+00:00 app[web.1]: cache: [GET /assets/border-a3c571a354b9381740db48aeebfaa63a.jpg] miss

如果我正确理解管道,那么对于我从浏览器发出的每个请求,这不应该是“错过”的,但应该找到它在缓存中。

阅读 Heroku 文档,您可以找到这样的解释:

Rails 3.1 provides an assets:precompile rake task to allow the compilation penalty to be paid up front rather than each time the asset is requested. If this task exists in your app we will execute it when you push new code.

但是“assets:precompile”任务应该如何?我尝试从头开始使用 Rails 3.1 构建一个项目来尝试找出答案,但在裸项目中没有这样的任务。或者我错过了什么?我怎样才能在缓存中找到资产?也许只是配置问题。

这些是我的生产配置文件的选项:

config.serve_static_assets = false
config.assets.compress = true
config.assets.compile = true # If I turn this off I get a 500 error and logs say that an  asset isn't compiled

我的 application.rb 有这一行:

config.assets.enabled = true

非常感谢您的帮助!

I've just upgraded my app on Heroku from Rails 3.0 to 3.1, and I'm trying to make the assets pipeline work. The main issue is that I can read from the heroku log the following kind of lines, for every asset:

2011-09-03T16:35:28+00:00 app[web.1]: cache: [GET /assets/border-a3c571a354b9381740db48aeebfaa63a.jpg] miss

If I understand the pipeline correctly, this should not be "miss" for every request I make from a browser, but it should be found in the cache.

Reading the Heroku docs you can find this explanation:

Rails 3.1 provides an assets:precompile rake task to allow the compilation penalty to be paid up front rather than each time the asset is requested. If this task exists in your app we will execute it when you push new code.

But how should that "assets:precompile" task be? I tried building a project with rails 3.1 from scratch to try to find out, but there is no such task in a bare project. Or am I missing something? How could I make that the assets are found in the cache? Maybe is just an issue with configuration.

These are the options of my production config file:

config.serve_static_assets = false
config.assets.compress = true
config.assets.compile = true # If I turn this off I get a 500 error and logs say that an  asset isn't compiled

My application.rb has this line:

config.assets.enabled = true

Thanks a lot for your help!

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

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

发布评论

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

评论(4

深海里的那抹蓝 2024-12-09 13:47:12

另外,请查看 http://guides.rubyonrails.org/asset_pipeline.html#precompiling-assets

为了更快地预编译资源,您可以部分加载您的应用程序
通过将 config.assets.initialize_on_precompile 设置为 false
config/application.rb,尽管在这种情况下模板看不到
应用程序对象或方法。 Heroku 要求这是错误的

Also, take a look at http://guides.rubyonrails.org/asset_pipeline.html#precompiling-assets

For faster asset precompiles, you can partially load your application
by setting config.assets.initialize_on_precompile to false in
config/application.rb, though in that case templates cannot see
application objects or methods. Heroku requires this to be false

甜点 2024-12-09 13:47:12

我想知道同样的事情,但这里有一个提示可以帮助确定您的资产是否实时编译或未

  1. 在本地运行 rake assets:precompile
  2. 对您的 css 进行一些更改,但不要重新运行rake 任务
  3. git add、commit 并推送到 heroku

如果您在步骤 2 中所做的更改显示在 heroku 上,那么您就知道您的应用程序正在实时编译

不要忘记您现在负责 http 缓存自从清漆不再包含在 celadon 中,因此您需要自己设置rack-cache 和 memcached:

但是,是的,我也发现这令人困惑

I was wondering the same thing, but here's a tip to help figure out if your assets are live-compiling or not

  1. run rake assets:precompile locally
  2. make some changes to your css but do not rerun the rake task
  3. git add, commit and push to heroku

If the changes you made in step 2 show up on heroku, then you know your app is live-compiling

Don't forget that you are now in charge of http caching since Varnish is no longer included on celadon, so you need to set up rack-cache and memcached yourself:

But yeah, I found this puzzling too

天邊彩虹 2024-12-09 13:47:12

您可以尝试将 config.serve_static_assets 设置为 true 并将

config.action_dispatch.x_sendfile_header = "X-Sendfile"

其添加到您的 config/environments/production.rb 文件中吗?

当您将代码推送到 Heroku 时,您应该会看到 slug 编译器 AFAICT 宣布的预编译。

Can you try with config.serve_static_assets set to true and

config.action_dispatch.x_sendfile_header = "X-Sendfile"

added to your config/environments/production.rb file?

When you push your code to Heroku you should see the precompiling announced by the slug compiler AFAICT.

安静 2024-12-09 13:47:12

确保您位于 Heroku“Cedar” 堆栈。然后Heroku 将在 slug 编译期间自动预编译您的资源

注意:我仍然遇到“缓存未命中”问题,但我认为这不是真的,因为如果您的资产未编译,您的应用程序将无法工作。

Make sure you are on the Heroku "Cedar" stack. Then Heroku will automatically precompile your assets during slug compilation.

Note: I'm still getting "cache misses" too, but I don't think that's really true because your app wouldn't work if your assets weren't compiled.

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