问题
Since I moved to active_admin my local server takes over 1.5 minutes to load each and every page. I'm surely doing something wrong.
Development.rb
config.assets.compress = true; config.assets.debug = true; config.assets.compile = false; config.assets.digest = false
Production.rb
config.assets.compress = true; config.assets.compile = true; config.assets.digest = true; config.assets.precompile += ['active_admin.js', 'active_admin.css']
Note the compile is true in production because active admin does not work other wise.
assets folder
--javascripts
-----active_admin.js
-----application.js loads its files from //= require_tree ./myfolder/
-----myfolder
----------1.js
----------2.js
----------....
--stylesheets
-----active_admin.css.scss
-----application.css.scss loads its files from *= require_tree ./myfolder/
-----myfolder
----------1.css.scss
----------2.css.scss
----------....
Logs
Seems to be because of the load time of each of the assets files. I m listing only the first and last. The time difference between the two is 1.5 minutes.
Started GET "/assets/jquery.js?body=1" for 127.0.0.1 at 2011-10-24 18:19:41 +0530 Served asset /jquery.js - 200 OK (4ms)
Started GET "/assets/myfolder/vertical_menu.css?body=1" for 127.0.0.1 at 2011-10-24 18:21:04 +0530 Served asset /myfolder/vertical_menu.css - 200 OK (2ms)
WHAT AM I DOING WRONG?
回答1:
The correct settings for development.rb are:
config.assets.debug = true; config.assets.compile = true;
You should remove the compress line, as this is quite an expensive process time-wise and may be the reason it is slow.
I would suggest looking at the asset pipeline Rails guide as this has the correct settings for an upgraded app's config files, and some tips about deploying too.
If you don't need to do any debugging on the files you could also remove debug; this will serve just one files instead of many.
回答2:
Take a look at https://github.com/wavii/rails-dev-tweaks.
Rails is running all of the to_prepare hooks on every Sprockets asset request in development mode. This includes things like auto-(re)loading your code, and various gems sneak work in there too. (Active Admin is one of these gems)
rails-dev-tweaks disables to_prepare & reloading on any asset request (and a few others - read the first part of its README). Speeds up your dev environment by a huge amount for any decently sized project. It's also configurable to do this for any additional requests you like
回答3:
In your production.rb can you try adding
config.assets.compile = false
And then run
bundle exec rake assets:precompile
This should create application-somemd5.js and application-someothermd5.css in your public/assets directory, and in production mode those precompiled assets will be served rather than re-compiling the asset pipeline with each page load.
EDIT:
Actually, I think you may need to make the rake command something like this:
bundle exec rake RAILS_ENV=production RAILS_GROUPS=assets assets:precompile
The RAILS_GROUPS part depends upon how you have your Gemfile setup. You'll need that if you have a section sort of like this:
group :assets do
gem 'jquery-rails'
gem 'sass-rails'
.... etc
end
来源:https://stackoverflow.com/questions/7875968/somethings-wrong-with-assets-each-page-in-local-takes-over-1-5-mins-to-load