2

I am trying to optimize my website and one of the suggestions I got was to defer parsing of JavaScript. I have googled it for a couple of hours but I haven't come across an elegant solution to do this in Rails 3. I am using the standard

<%= javascript_include_tag :application -%>

tag in my code, just before . Does anybody know a relatively simple way to defer the loading of all the Javascript of the application.js file? Thanks.

Snels Nick
  • 925
  • 3
  • 13
  • 25
  • @phoet He is probably refering to a website speed test, where this is a common advice. "294.4KiB of JavaScript is parsed during initial page load.Defer parsing JavaScript to reduce blocking of page rendering." See: http://gtmetrix.com/ – yas4891 Nov 25 '12 at 04:47
  • You are stating that you have the tag "just before ." - which word is missing here? – yas4891 Nov 25 '12 at 05:05
  • <\head> is missing :) It is indeed to improve the score on a speed test. Javascript should be loaded at the end of the page load. Haven't found a solution yet, so if anyone has any ideas... – Snels Nick Nov 26 '12 at 11:14

1 Answers1

5

I know this is an old question, but in case someone is still looking for a solution: I solved the problem moving the <%= javascript_include_tag 'application' %> to the end.

  ....
  <%= stylesheet_link_tag 'application', :media => 'all' %>
</head>
<body>
  ...
</body>
  <%= javascript_include_tag 'application' %>
</html>

I hope it helps someone...

gabrielhilal
  • 10,660
  • 6
  • 54
  • 81