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.
npm install deferred-scripts
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();