Absurdly simple on-demand script loader.
$ npm install scriptloader
$ component install timoxley/scriptloader
varload=require('scriptloader')load('//my-widget.js')// load js from current domainload('//remote.com/their-widget.js')// load js from remote domain// returns the script. you can listen for load/error on this directlyload('//cdnjs.cloudflare.com/ajax/libs/json3/3.2.4/json3.min.js').addEventListener('load',function(){console.log('it is loaded')})// or just supply a callbackload('//cdnjs.cloudflare.com/ajax/libs/json3/3.2.5/json3.min.js',function(err,script){console.log('it is loaded')})// you can also specify a target document where you want the script to be loadedload(iframe.contentWindow.document,'//cdnjs.cloudflare.com/ajax/libs/json3/3.2.5/json3.min.js',function(err,script){console.log('it is loaded')})scriptloader appends a script tag to your document.body with the src
attribute set to the script you desire to load.
Interesting problem. Unfortunately we can't use domify to do this
since <script> src attributes don't trigger remote loading
if they're created using innerHTML, which is how domify works.
- Consider removing
<script>after it loads? - Investigate script's
asyncattribute.
MIT