如何使Rails 3资产预编译更快? [英] How can I make Rails 3 assets precompile faster?
问题描述
deploy:assets的 deploy / assets
:预编译
任务。 除了编译本身很慢之外,一切工作都很好。我没有那么多的CSS和JavaScript(总共约8200行)。
编译资源大概需要1-3分钟,占整个部署时间的90%。
有没有办法优化这个?可能使用不同的过程来编译资产或以某种方式进行优化?
我在1.9.2-p290上的Linode 512上运行应用程序,Rails 3.2.1和使用 therubyracer
gem,如果有任何相关性。
对于使其运行速度更快的答案,但是就不同的程序而言,您可以告知Capistrano只有在实际对您的资产进行任何更改时,才能预编译资产。您将需要执行一个自定义的 assets:precompile
任务,这将查看现有和新部署的代码之间的git日志。对我来说,这样做很好,现在我只需要在更新资源时处理缓慢的部署:
命名空间:deploy do
命名空间:assets do
任务:precompile,:roles => :web,:except => {:no_release =>如果捕获(cd#{latest_release}&#{source.local.log(from)}供应商/资产/应用程序/资产,则为
from = source.next_revision(current_revision)
/ | wc -l)。to_i> 0
run%Q {cd#{latest_release}&& #{rake} RAILS_ENV =#{rails_env}#{asset_env} asset:precompile}
else
logger.info由于没有资产更改而跳过资产预编译
end
end
end
end
资料来源: http://www.bencurtis.com/2011/12/skipping-asset-compilation- with-capistrano /
I have a running Rails 3.2.1 application, that I'm deploying via Capistrano with the deploy/assets
which runs the deploy:assets:precompile
task.
Everything works just fine, except that the compilation itself is really slow. I don't have that much CSS and JavaScript (about 8200 lines total).
It generally takes about 1-3 minutes to compile the assets, which is about 90% of the whole deployment time.
Is there any way to optimize this? Maybe use a different procedure to compile the assets or somehow optimize it?
I'm running the app on Linode 512 on 1.9.2-p290, Rails 3.2.1 and using therubyracer
gem if that's of any relevance.
This isn't an answer on making it run faster, but as far as a "different procedure" goes, you can tell Capistrano to only precompile assets when you've actually made any changes to your assets. You would want to do a custom assets:precompile
task something like this, which would look at the git logs between the existing and newly deployed code. For me, this worked great and now I only need to deal with slow deployment when updating assets:
namespace :deploy do
namespace :assets do
task :precompile, :roles => :web, :except => { :no_release => true } do
from = source.next_revision(current_revision)
if capture("cd #{latest_release} && #{source.local.log(from)} vendor/assets/ app/assets/ | wc -l").to_i > 0
run %Q{cd #{latest_release} && #{rake} RAILS_ENV=#{rails_env} #{asset_env} assets:precompile}
else
logger.info "Skipping asset pre-compilation because there were no asset changes"
end
end
end
end
Source: http://www.bencurtis.com/2011/12/skipping-asset-compilation-with-capistrano/
这篇关于如何使Rails 3资产预编译更快?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!