【发布时间】:2013-08-13 05:59:50
【问题描述】:
有没有办法在 Heroku 上缓存 Rails 4 应用程序的预编译资产?
我按照 this blog post 和一些 heroku 文档的说明进行操作,这大大加快了速度,但预编译资产仍然需要同样长的时间。
这是我的 gemfile 中的相关部分(也发现有必要 enable the 'user-env-compile' lab):
group :production, :staging do
# for heroku, see https://devcenter.heroku.com/articles/rails-integration-gems
gem 'rails_12factor'
# https://devcenter.heroku.com/articles/rack-cache-memcached-rails31
gem 'rack-cache'
gem 'kgio'
# faster heroku deploys (http://blog.alexmaccaw.com/faster-deploys)
gem 'memcachier'
gem 'dalli'
end
从我的 config/production.rb 和 config/staging.rb:
# Neither of the below worked (tried separately)
# config.assets.cache_store = :dalli_store
config.assets.configure {|env| env.cache = ActiveSupport::Cache.lookup_store(:dalli_store) }
谢谢!
【问题讨论】:
-
您是想缩短资产编译时间,还是尝试在别处编译资产,这样它们就不必由您的应用程序编译? “大大加快速度”和“一种缓存预编译资产的方法”对我来说听起来像是不同的任务。
-
This Dev Center article 包含有关缓存静态资产的信息,并在 this blog post 中进行了扩展
-
尽量避免重新编译未更改的资产,因为这似乎使部署需要很长时间。本地预编译是唯一的方法吗?
-
开发中心文章中提到了三个选项:在本地编译、在 slug 编译期间编译和在运行时编译。我猜你不想要运行时,因为它可能会减慢你的应用程序?
-
博客文章提到“如果您将自己编译的资产推送到源代码控制中,Heroku 将识别这一点,并且不会尝试其他预编译”。他似乎暗示我们应该不这样做,因为这是另一个可能出错的地方。但是,如果您有大量未更改的资产,也许将它们签入源代码控制对您有用?