为什么资产管道在Rails 3.1中放慢了localhost

我一直注意到Rails 3.1中资产管道的页面加载时间令人难以置信。 每个资产(css / js / image)的加载时间都在半秒到一秒之间。 这真的开始阻碍发展。 我在生产中没有同样的问题。

有没有解决方法? 下面的日志文件显示了每个单独资产在0.5到0.3秒内的加载情况:

# load of page itself...
...
Completed 200 OK in 1231ms (Views: 933.0ms | ActiveRecord: 15.6ms)


Started GET "/assets/blueprint/screen.css?body=1" for 127.0.0.1 at 2012-01-15 15:53:00 +0000
Served asset /blueprint/screen.css - 304 Not Modified (0ms)


Started GET "/assets/application.css?body=1" for 127.0.0.1 at 2012-01-15 15:53:00 +0000
Served asset /application.css - 304 Not Modified (0ms)


Started GET "/assets/blueprint/print.css?body=1" for 127.0.0.1 at 2012-01-15 15:53:00 +0000
Served asset /blueprint/print.css - 304 Not Modified (0ms)


Started GET "/assets/universal/application.js?body=1" for 127.0.0.1 at 2012-01-15 15:53:01 +0000
Served asset /universal/application.js - 304 Not Modified (2ms)


Started GET "/assets/universal/animate-color.js?body=1" for 127.0.0.1 at 2012-01-15 15:53:01 +0000
Served asset /universal/animate-color.js - 304 Not Modified (0ms)


Started GET "/assets/universal/animate-shadow.js?body=1" for 127.0.0.1 at 2012-01-15 15:53:02 +0000
Served asset /universal/animate-shadow.js - 304 Not Modified (0ms)


Started GET "/assets/jquery_ujs.js?body=1" for 127.0.0.1 at 2012-01-15 15:53:02 +0000
Served asset /jquery_ujs.js - 304 Not Modified (0ms)


Started GET "/assets/universal/jquery.placehold.js?body=1" for 127.0.0.1 at 2012-01-15 15:53:02 +0000
Served asset /universal/jquery.placehold.js - 304 Not Modified (0ms)


Started GET "/assets/universal/autoresize.js?body=1" for 127.0.0.1 at 2012-01-15 15:53:03 +0000
Served asset /universal/autoresize.js - 304 Not Modified (0ms)


Started GET "/assets/universal/utilities.js?body=1" for 127.0.0.1 at 2012-01-15 15:53:03 +0000
Served asset /universal/utilities.js - 304 Not Modified (0ms)


Started GET "/assets/universal/validators.js?body=1" for 127.0.0.1 at 2012-01-15 15:53:03 +0000
Served asset /universal/validators.js - 304 Not Modified (0ms)


Started GET "/assets/jquery.js?body=1" for 127.0.0.1 at 2012-01-15 15:53:04 +0000
Served asset /jquery.js - 304 Not Modified (0ms)


Started GET "/assets/whitelabel/pingpanel/pingpanel.css?body=1" for 127.0.0.1 at 2012-01-15 15:53:04 +0000
Served asset /whitelabel/pingpanel/pingpanel.css - 304 Not Modified (0ms)


Started GET "/assets/logo.png" for 127.0.0.1 at 2012-01-15 15:53:05 +0000
Served asset /logo.png - 304 Not Modified (0ms)


Started GET "/assets/application_bar_background.png" for 127.0.0.1 at 2012-01-15 15:53:05 +0000
Served asset /application_bar_background.png - 304 Not Modified (0ms)


Started GET "/assets/linen-new.jpg" for 127.0.0.1 at 2012-01-15 15:53:06 +0000
Served asset /linen-new.jpg - 304 Not Modified (0ms)

铬网络分析仪可以更清楚地看到放缓的影响:

在这里输入图像描述


每当资产加载时,它必须通过Rails env传递,Rails将重新加载所有代码。 当你拥有大量的资产时,它会加起来减慢页面加载速度。

尝试使用rails-dev-tweaks gem,它可以让您更好地控制Rails重新加载代码的时间。 应该解决你的放缓问题。


由于Sprockets不使用自动加载器,因此可以通过rails-dev-tweak获得有限的改进。 链轮被安装为传统路线。

转到您的development.rb文件并设置:

config.assets.debug = false

这将改变开发模式只提供一个文件,而不是很多,这应该加快一点。

如果您需要执行一些源代码调试,并且添加debug = 1,则URL参数将告诉Sprockets为该请求分割文件。

链接地址: http://www.djcxy.com/p/50005.html

上一篇: Why has the asset pipeline slowed localhost in Rails 3.1

下一篇: Rails 3.1 and functionless jQuery