0

I'm adding some js script like this:

  const script = document.createElement('script');
  script.src = 'https://cdn.some/file.js';
  script.async = true;
  script.setAttribute('type', 'text/javascript');
  document.body.appendChild(script);

What is the use of .async = true; ?

pmiranda
  • 7,602
  • 14
  • 72
  • 155
  • It means the script is executed asynchronously with the rest of the page (the script will be executed while the page continues the parsing) – Spectric Mar 31 '21 at 14:11
  • Not sure there is a point - don't dynamically injected scripts run only once the page is parsed anyway? – CertainPerformance Mar 31 '21 at 14:14
  • hm, si I don't need that they be loaded asynchronously, I won't use "true" then, I wonder what's the default value. Of course I need them to be loaded synchronously, I need them first some other scripts – pmiranda Mar 31 '21 at 14:17
  • 1
    @pmiranda Default value should be false. – Spectric Mar 31 '21 at 14:53

0 Answers0