Search code examples
javascriptruby-on-railscsshamlwebrick

Rails pageload slow because of CSS & JS files. 304 not modified error


I converted all my html files to jquery yesterday and page requests started being really slow. In the console I see messages like this for every css and js file that I have:

Started GET "/assets/application.css?body=1" for 127.0.0.1 at 2011-10-21 10:00:11 +0200
Served asset /application.css - 304 Not Modified (0ms)

Even though it takes '0ms' to load, the server seems to wait between every file resulting in every pageload taking about 10-15 seconds. Any idea what could be causing this? I read everywhere that HAML should be just as fast as erb.

Also when I look with the chrome developer tool for each file, it says 1-5 seconds waiting for each file, while receiving only takes 0-1ms.


Solution

  • The problem is that in development mode with each request your Rails application will reload all classes which dramatically slows down the requests.

    You could merge all Javascript and CSS into a single file by disabling asset debugging. That way you'll only have two requests (one Javascript, one CSS).

    Another way is to use a gem like rails-dev-tweaks which disables certain Rails features for asset requests.