Why has the asset pipeline slowed localhost in Rails 3.1
I've been noticing incredibly slow page loading times with the asset pipeline in Rails 3.1. Each asset (css/js/image) is taking between half a second and a second to load. This is really starting to hamper development. I don't have the same problems in production.
Is there any solution? The log file below shows how each individual asset is loading in 0.5 - 0.3 of a second:
# 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)
The effect of the slowdown can be more clearly seen in the chrome network analyser:
Whenever an asset is loaded, it has to be passed through the Rails env and Rails will reload all the code. When you have a lot of assets it will add up to slow page loads.
Try the rails-dev-tweaks gem which gives you more control over when Rails reloads code. Should fix your slowdown issues.
You may get a limited improvement with rails-dev-tweaks because Sprockets does not use the autoloader. Sprockets is mounted as a traditional route.
Go to your development.rb file and set:
config.assets.debug = false
This will change dev mode to serve only one file instead of many, and this should speed things up a bit.
If you need to do some source debugging adding debug=1 as a URL param will tell Sprockets to split the files for just that request.
链接地址: http://www.djcxy.com/p/50006.html上一篇: 流体网站是否值得再做?