After I added Sprockets, Rails is loading very slow in development mode, what should I do to speed it up?
-
Could you provide: the part of the Gemfile you changed, is it Rails 3.1 or a modified Rails 3.0.x application, what is your configuration in development mode for assets? – mliebelt Sep 23 '11 at 07:36
5 Answers
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.
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

- 7,951
- 4
- 41
- 50
-
Nice gem, it made asset serving useful. Rails was taking forever to load a single page that had too many assets. – Ian Oct 01 '11 at 17:39
-
2
-
-
Be very careful. Hours and Hours of dev time has been lost because of this gem. – JZ. May 09 '12 at 06:21
-
What issues did you run into? If you have some time, cut a github issue to the project; I'd be interested in seeing how your workflow differs & is impacted by it. – Nevir May 09 '12 at 14:31
After referring to several Google results regarding this issue, I've nailed down where the DNS issue resides.
The problem is: Rails is doing reverse lookups. So, if you request from a direct IP, or a hostname in the /etc/hosts of only the machine with the browser, which i do often because i run everything in thrown together VM's, and that IP doesn't resolve to something quickly in the dev server, Rails will wait, for each, and every request.
Moral of the story? Include a /etc/hosts entry for every IP related to your development on the dev server (i.e. the server running rails). This means to go ahead and make a hosts entry for every fake/virtual/etc... IP on the dev server you expect to be involved in rails testing, because when it logs requests and whatnot, it will do a reverse lookup, and you want that to be speedy.

- 131
- 1
- 5
-
-
I wish this answer was phrased better because I can't get my head around it. – Thomas Potaire Feb 11 '15 at 00:30
Weird solution that worked for me. I normally navigated to my app on development via myapp.local:3000, which was set in my hosts file. Assets were loading ridiculously slow.
By navigating to my app via 127.0.0.1:3000, the assets loaded quickly, and further, after using the local ip one time, I could then navigation using myapp.local:3000 and the assets were loading super fast now.
Wish I could tell you why, but I hope it helps someone out there. I'm on OSX 10.7.5.

- 682
- 5
- 9
Also check out Turbo Sprokets here - https://github.com/ndbroadbent/turbo-sprockets-rails3
It looks promising.

- 8,814
- 3
- 32
- 22
-
2That only speeds `assets:precompile` and development environment compiles on the fly. – Turadg Feb 27 '13 at 19:35
Have you looked at how quickly it runs in production? The development environment behaves differently than testing and production, and takes more performance hits because of it. Without more information, we can't provide you with a better answer.

- 14,005
- 5
- 37
- 49