deferred-scripts
v0.0.4
Published
Defer <script> tag loading until needed.
Downloads
1
Readme
deferred-scripts
Defer <script>
tag loading until needed.
If you have third party scripts you are unable to load until the user has given consent you can use this to defer them.
Installation
npm install deferred-scripts
Example
var deferredScripts = new DeferredScripts();
// addScript(sourceURL, onLoadCallback)
deferredScripts.addScript('https://www.google-analytics.com/ga.js', function() {
// Onload
console.log('Loaded GA')
})
// addPartial(sourceURL)
deferredScripts.addPartial('./my-partial.html')
// onLoadCallback is optional
deferredScripts.addScript('https://www.google-analytics.com/ga.js')
// When you're ready to load the scripts
deferredScripts.loadScripts();