@yr/async-loader
v1.1.0
Published
A simple inline-able script loader
Downloads
2
Readme
A lightweight script loader, with callback support.
Usage
Place async-loader.min.js
in the <head>
:
<script src="async-loader.min.js"></script>
<!-- Or preferably inlined -->
<script>!function(){window.asyncLoader=function(e,n){var t=document.createElement("script"),a=document.getElementsByTagName("script")[0];t.async=!0,t.src=e,"function"==typeof n&&(t.onload=function(){n(),t.onload=t.onreadystatechange=null},t.onreadystatechange=function(){("loaded"===t.readyState||"complete"===t.readyState)&&t.onload()}),a.parentNode.insertBefore(t,a)}}();</script>
...and load your script files, optionally executing a callback when loading is complete:
<script>
asyncLoader('//www.google-analytics.com/analytics.js', function () {
ga('create', 'UA-XXXXXXX', 'mydomain.com');
ga('send', 'pageview');
});
</script>