question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support "defer" as well as "async"?

See original GitHub issue

It might be nice if this could handle defer scripts as well as async, as an option.

e.g. having a consolidated interface to allow notification either type of scripts being parsed. Would allow async scripts to wait on defer ones, etc.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:3
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
asos-tompcommented, May 24, 2019

Yep - I guess this is a similar request to https://github.com/muicss/loadjs/issues/84 - if there’s an easy way to set those flags innately in the library, would prevent a lot of extra boilerplate needed in consumers. And should hopefully be a tiny change?

2reactions
amoreycommented, May 23, 2019

Let me think about this some more… in the mean time you can use the before callback to set the defer attribute:

loadjs(['/path/to/foo.js', '/path/to/bar.js'], {
  success: function() {},
  error: function(pathsNotFound) {},
  before: function(path, scriptEl) {
    scriptEl.setAttribute('defer', 'defer');
  }
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

Async & Defer - What's The Difference? - Page Speed Checklist
async and defer both load JavaScript asynchronously without render blocking, but async executes as soon as possible while defer runs in sequence toward...
Read more >
How and when to use Async and Defer attributes | Zell Liew
defer waits for DOM to be loaded before it executes. This means: You should use defer if your script requires the DOM.
Read more >
Eliminate Render-Blocking JavaScript with Async and Defer
Async and defer are two HTML5 attributes that allow delaying execution of scripts, eliminating blocking JavaScript. A must for performance!
Read more >
Can you use both the async and defer attributes on a HTML tag?
The defer attribute may be specified even if the async attribute is specified, to cause legacy Web browsers that only support defer (and...
Read more >
Efficiently load JavaScript with defer and async - Flavio Copes
if you specify both, async takes precedence on modern browsers, while older browsers that support defer but not async will fallback to defer ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found