deferred-scripts

0.0.4 • Public • Published

deferred-scripts

Build Status Coverage Status npm

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();

Readme

Keywords

Package Sidebar

Install

npm i deferred-scripts

Weekly Downloads

0

Version

0.0.4

License

MIT

Last publish

Collaborators

  • nickromano