4

I have a standart rails 3 webapp with the default asset pipeline. All of a sudden, the assets took a very long time to load (my page loads went to ~1-2secs to ~1min). The server response time (/home) is normal, but some .css and .js files are pending for very long (up to 45 seconds). The only few assets that take this long are those provided by gems (eg: modernizr-rails/vendor/assets/javascripts/modernizr.js)

For example, for modernizr.js?body=1 :

Headers:

Request URL:http://dev.sharewizz.com:3000/assets/modernizr.js?body=1
Request Method:GET
Status Code:304 Not Modified

Stats:

DNS Lookup  5.00 s
Connecting  20.07 s
Sending     0
Waiting     10 ms
Receiving   3 ms

It it a problem with sprockets ? How do I know what's wrong ?

Notes: all other browsers behave the same. Edit: Actually the problem is only with chrome, not even safari. I've tried to launch my server with rails s on port 3000 and on port 80 (no changes)

If I access http://localhost:3000/assets/modernizr.js?body=1, most of the times it is instant, sometimes it wait for very long.

New Alexandria
  • 6,951
  • 4
  • 57
  • 77
Benjamin Crouzier
  • 40,265
  • 44
  • 171
  • 236

3 Answers3

11

Another option - HDD isn't fast enough for logs, just bump into this (suddenly) on my dev pc. Try to set this into config/development.rb:

# Expands the lines which load the assets
config.assets.debug = false #true

If you have a lot of assets, each one take the time to write into dev log, adding up to several minutes total.

lifecoder
  • 1,424
  • 1
  • 14
  • 29
3

There is an issue in chrome where the browser tries a dns request and waits for a timeout (you can see in the developer tools / network tab if you hover on the colored timelines, it says waiting (30000ms or higher), receiving (4ms).

In the case you are soing something like this: 127.0.0.1 localhost.mysite.com in hostfile, and access http://localhost.mysite.com in the browser), you might try to just access it with localhost on port 80:

  • Start rails with rvmsudo rails server -p 80
  • Access http://localhost in chrome

That might solve the issue.

Benjamin Crouzier
  • 40,265
  • 44
  • 171
  • 236
  • This other question may also help some people on OS X >= Lion: http://superuser.com/questions/313128/lion-name-resolution-order – Sami Samhuri Dec 17 '13 at 23:09
0

Precompile your assets and enable asset pipelining for development env. This may however not load the changes that you make in your source code without restarting the server.

Nerve
  • 6,463
  • 4
  • 29
  • 29
  • `rake assets:precompile;` then `rails server -e production`. No errors. But I get a 404 not found on application-701b5....js and .css. `ls public/assets/application` and I see application-701b5....js. The exact same file. – Benjamin Crouzier Apr 04 '13 at 12:43
  • Had to put `config.serve_static_assets` to `true` in `production.rb`. (see http://stackoverflow.com/questions/7736031). Everything is fast in production mode. – Benjamin Crouzier Apr 04 '13 at 12:50
  • If I switch back to development, it's slow again (pages does not take an extra few seconds, but minutes). I want to develop in development env anyway, so I'm solving this problem. – Benjamin Crouzier Apr 04 '13 at 12:52