【发布时间】:2014-09-02 16:34:01
【问题描述】:
我在我的 Rails 应用程序中提供资产时遇到了很大的麻烦。在我的 VPS 上加载一个 2KB 的图像(由 nginx 直接提供,而不是 Rails 提供)需要 42 毫秒。在 Heroku 上加载它有时可能需要超过 1 分钟。
奇怪的事实是,此时应用程序只是一堆通过高压提供的静态页面。
我所有的资产都是在本地预编译的。我安装了 rails_12factor 和 heroku_rails_deflate gem。
这是我的 Sprockets 配置:
config/initializers/assets.rb
# Version of your assets, change this if you want to expire all your assets.
Rails.application.config.assets.version = '1.0'
# Precompile additional assets.
# application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
Rails.application.config.assets.precompile += %w( pages/home.js )
config/environments/production.rb
# Disable Rails's static asset server (Apache or nginx will already do this).
config.serve_static_assets = true
# Compress JavaScripts and CSS.
config.assets.compress = true
config.assets.js_compressor = :uglifier
config.assets.css_compressor = :sass
# Do not fallback to assets pipeline if a precompiled asset is missed.
config.assets.compile = false
# Generate digests for assets URLs.
config.assets.digest = true
你有什么想法吗?
这是我的日志摘录:
14-07-11T23:48:54.917535+00:00 heroku[router]: at=info method=GET path="/assets/pages/home-dca14429ad8cf7d73be6230207124ab1.js" host=v2-interconn.herokuapp.com request_id=aefbec46-f505-45b9-b368-1ad5f7924c70 fwd="188.10.253.161" dyno=web.1 connect=1 service=3 status=200 bytes=916
2014-07-11T23:48:54.911470+00:00 heroku[router]: at=info method=GET path="/assets/application-a6b582f07af35ba97eef7b73812c37b9.js" host=v2-interconn.herokuapp.com request_id=3cf43d9f-e35b-4f62-8cbc-47121e07375b fwd="188.10.253.161" dyno=web.1 connect=0 service=8 status=200 bytes=917
2014-07-11T23:48:54.940930+00:00 heroku[router]: at=info method=GET path="/assets/ballicons/letter-0223f57c4a985183df154ed1219f260e.svg" host=v2-interconn.herokuapp.com request_id=6c7a7b12-683e-42e7-9975-6ee58b17821e fwd="188.10.253.161" dyno=web.1 connect=1 service=2 status=200 bytes=940
2014-07-11T23:48:55.064240+00:00 heroku[router]: at=info method=GET path="/assets/ballicons/laptop-5ac5cd546c687e0bbba1e4043c5f62f8.svg" host=v2-interconn.herokuapp.com request_id=9a659d8b-8998-4f02-b8b3-edd1a6cfb34c fwd="188.10.253.161" dyno=web.1 connect=3 service=3 status=200 bytes=940
编辑
问题是 Heroku 的 resolved。感谢所有帮助过的人! :)
【问题讨论】:
-
这很糟糕,你需要修复它。您确定您的 heroku 应用程序正在生产模式下运行吗?检查
heroku config,也许它正在登台环境中运行?也许您还在使用 webrick 服务器? -
Heroku 正在生产中运行,我使用 Thin 作为 Web 服务器。
-
支持帮不了你?他们应该对自己的系统有更多的了解
-
我已经开了一张票。希望他们至少对可能发生的事情有所了解。
-
可能和我类似的post here有关
标签: ruby-on-rails heroku assets sprockets