Ruby on Rails Sunday, May 3, 2015

With Turbolinks pages will change without a full reload, so you can't
rely on DOMContentLoaded or jQuery.ready() to trigger your code. Instead
Turbolinks fires events on document to provide hooks into the lifecycle
of the page.

But I found DOMContentLoaded event is actually triggered when javascript
is placed at the bottom of body tag, so for example, DOMContentLoaded
will be triggered if I switch between pages using the following layout:

<!DOCTYPE html>
<html>
<head>
<title>Turbolinks</title>
<%= stylesheet_link_tag 'application', media: 'all',
'data-turbolinks-track' => true %>
<%= csrf_meta_tags %>
</head>
<body>
<div id="container">
<%= yield %>
</div>
<%= javascript_include_tag 'application' %>
</body>
</html>

However, the DOMContentLoaded won't be triggered if javascript is placed
in head tag. I read the source code of Turobolinks gem but I still don't
understand why. Thanks!

--
Posted via http://www.ruby-forum.com/.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/6d8395c5fd45e9d53b2282d935a27d67%40ruby-forum.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment