Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 303308

Call Drupal.attachBehaviors on async script load

$
0
0

Hi there,

Problem/Motivation

When we add the attribute { async : true } in a js libraries, the script tag resulting in HTML source get the async attribute. That is very helpfull to optimize pageload speed when the library is not necessary for first render. When doing that, the custom behaviors are randomly executed due to the moment where domready is called, the browser, etc.
Firefox execute it some times, Chromium never, and so on.
I would like to write js behaviors capable to be ran on synchronous or asynchronous libs.

Proposed resolution

I propose to add an eventListener on async (and defer ?) script tags to execute Drupal.attachBehaviors() on asynchronous scripts too.
No sure what's the best place to do it, the patch proposes to insert it on drupal.init.js


Viewing all articles
Browse latest Browse all 303308

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>