javascript - jQuery ready event does not fire on every page load when placed in HEAD in Rails -


i'm noticing strange when using jquery ready event in rails. if handler added in <head> section, either directly within script tags or in asset pipeline files included using <%= javascript_include_tag ..., execute on first page request, , not on subsequent requests. is, explicit browser actions load/refresh page execute it, new page views triggered clicking around on links not.

on other hand, if it's included in <body>, fire every time on every page view- you'd expect.

<head> <script> jquery(document).ready(function(){     console.log('ready in head'); // fires on first page load }); </script> </head>  <body> <script> jquery(document).ready(function(){     console.log('ready in body'); // fires every time }); </script> </body> 

really confused. i'm seeing in rails apps, don't understand how rails effect jquery client-side technology??

from railsapps project :

the rails asset pipeline become more important in rails 4.0 new turbolinks feature. turbolinks improves performance keeping current page instance alive , replacing page body (plus title in head). long head element identical between pages, turbolinks mechanism can deliver “turbo” speed boost. adds importance of avoiding script tags on specific pages.


Comments