Search code examples
ruby-on-railsturbolinks

Rails 4 + Turbolinks: JS in the head or at the bottom of the body?


I'm used to sticking my JS at the bottom of my body element (as per HTML5Boilerplate), but since TurboLinks, which will be on by default in Rails 4, reloads the body (and title) on every request, would it make sense to put my JS in the head from now on? Are there any decent guides or best practices on this yet?


Solution

  • Also precompiled application.js (as per the assets pipeline) is on and in head by default. The reasoning is that even if the js is loaded before the rest of the page, as the js is always the same it will be loaded from cache from the second request onwards, so there is no actual reason to serve it at the bottom of the body anymore.