StimulusJS and Turbolinks

In the Rails world, when we using plain js or jQuery, there is the need to wait for the DOM to properly load using turbolinks:load before triggering running page load code, eg:

document.addEventListener('turbolinks:load', function(event) {
  if (typeof ga === 'function') {
    ga('set', 'location', event.data.url);
    return ga('send', 'pageview');
  }
});

What is the load order with StimulusJS. Can we assume that the DOM is fully loaded when running code in connect() or initialize() ?

1 Like

Yes, as of Stimulus 1.1 via Start when the DOM is interactive by javan · Pull Request #131 · hotwired/stimulus · GitHub

3 Likes