1

When I include a script whose loading fails with a timeout (e.g. via packets being dropped, such as the Chinese Great Firewall dropping all packets to Google Analytics), the browser favicon loading indicator keeps spinning until the timeout is over.

(Note on Linux, you can simulate such timeouts using iptables, e.g. sudo iptables -I OUTPUT -d 'IP_OF_GOOGLE_ANALYTICS_HERE' -j DROP.)

How do I have to place/annotate a <script> so that it does not block the loading indicator?

I have tried various combinations (see articles here and here) of the defer and async attributes of <script> in <head> and <body>, but the spinner keeps spinning in my Chromium 68 and Firefox 63 Nightly.

Also, what exactly determines whether the spinner is shown or not? Is DOMContentLoaded the boundary, or are other things at play?

nh2
  • 24,526
  • 11
  • 79
  • 128

1 Answers1

0

Finally found it: the load event.

fired when a resource and its dependent resources have finished loading

That is when the spinner stops, after the red "load" line in the Chromium Network tab.

// `load` so that this doesn't block the favicon loading indicator
window.addEventListener("load", function(event) {
  const script = document.createElement('script');
  script.async = true;
  script.src = 'https://www.google-analytics.com/analytics.js';
  document.head.appendChild(script);
});
nh2
  • 24,526
  • 11
  • 79
  • 128
  • well, with onready I meant `load` or `DOMContentLoaded`, have you tested `DOMContentLoaded` and didn't work? https://stackoverflow.com/a/2414783/6121568 – Emeeus Aug 23 '18 at 22:34
  • @Emeeus Yes, I have tested `DOMContentLoaded` and it didn't work (as mentioned in my comment https://stackoverflow.com/questions/51985782/how-to-make-script-loading-not-block-the-browser-loading-indicator/51994877?noredirect=1#comment90939160_51987971). Should it? I guess it makes sense that `ready` is what makes the spinner stop? – nh2 Aug 29 '18 at 23:51
  • Honestly, I don't know. It seems like a feature that browsers could implement in different ways. – Emeeus Aug 30 '18 at 22:06