Facilitate async loading of quicklink.umd.js
Author: westonruterCreated Jan 24, 2019Updated Apr 28, 2023
Currently the readme suggests to include the script into the page via:
<!-- Include quicklink from dist -->
<script src="dist/quicklink.umd.js"></script>
<!-- Initialize (you can do this whenever you want) -->
<script>
quicklink();
</script>or at load event via:
<script>
window.addEventListener('load', () =>{
quicklink();
});
</script>However, shouldn't the quicklink.umd.js script be loaded with async to begin with? The blocking script is not good for performance.
Ideally you should be able to do something like this, similar to the AMP shadow doc API:
<script async src="dist/quicklink.umd.js"></script>
<script>
(window.quicklink = window.quicklink || []).push(function(quicklink) {
quicklink();
});
// Or...
window.addEventListener('load', () =>{
(window.quicklink = window.quicklink || []).push(function(quicklink) {
quicklink();
});
});
</script>Source: GoogleChromeLabs/quicklink