delay-script

1.0.1 • Public • Published

delay-script

Delay Loading of Non Critical Scripts

Features

  • Downloads all delayed scripts in parallel
  • Execute scripts in order they appear in html
  • Supports delaying Inline scripts as well
  • tiny 495 bytes

Setup

  • Include dist/delay-script.min.js code in your page
  • Set type="text/delay" on the scripts you wish to delay
  • Call loadDelayScripts when you want to load all the delay scripts

Example

View Example HTML

<script type="text/delay" src="foo.js"></script>
<script type="text/delay" src="bar.js"></script>
...
// load delay-scripts after load event is fired
window.addEventListener('load', () => {
	loadDelayScripts(() => {
		console.log('done');
	});
});

API

// loads the delay scripts
loadDelayScripts();

// loads the delay scripts and calls fn when all are delay scripts are loaded and executed
loadDelayScripts(fn);

Package Sidebar

Install

npm i delay-script

Weekly Downloads

1

Version

1.0.1

License

ISC

Unpacked Size

4.21 kB

Total Files

5

Last publish

Collaborators

  • manantank