npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@myspace-nu/resloader

v1.0.14

Published

A JavaScript resource loader featuring conditional loading, asynchronous- or sequential loading

Downloads

9

Readme

resLoader

A JavaScript resource loader featuring conditional loading, asynchronous- or sequential loading

Build Status GitHub

Installation

Using npm

npm install @myspace-nu/resloader --save

Using CDN

<script src="https://cdn.jsdelivr.net/npm/@myspace-nu/resloader/dist/resLoader.min.js"></script>

Or include the script manually

<script src="/path/to/resLoad.min.js"></script>

Usage

Simple usage

<script type="text/javascript">
	var loader = new resLoader();
	loader.load("myScript.js");
</script>

Now, that isn't very impressive. Let's load some more scripts and add a callback when all scripts are loaded.

<script type="text/javascript">
	var loader = new resLoader();
	loader.load({
		url: ["myScript.js","anotherScript.js"],
		onComplete: function(){
			console.log("All done");
		}
	});
</script>

Let's say that one script is depending on another to be loaded first, simply set async to false (default true).

<script type="text/javascript">
	var loader = new resLoader();
	loader.load({
		url: ["myScript.js","myScript-extra.js"],
		async: false,
		onComplete: function(){
			console.log("All done, and in the right order");
		}
	});
</script>

You can also add conditions for the resource to be loaded. Like, only load jQuery unless it is already loaded.

<script type="text/javascript">
	var loader = new resLoader();
	loader.load({
		url: "//code.jquery.com/jquery-3.3.1.min.js",
		loadUnless: window.jQuery,
		async:false,
		onComplete: function(){
			$("body").append("<p>One more paragraph</p>");
		}
	});
</script>

Note that onComplete is called regardless of the test is evaluted to true or false, i.e. in the example the code will be executed even if jQuery has been loaded earlier on the page

If you include different resources to the same html out and there is a chance that several of the resources include for example jQuery you can solve this by loading these scripts in blocking mode like this.

<script src="/path/to/resLoad.min.js"></script>
<script type="text/javascript">
	var loader = new resLoader();
	loader.load([
		{ url:"//code.jquery.com/jquery-3.3.1.min.js", unless:window.jQuery, blocking:true }
	]);
</script>
...
<script type="text/javascript">
	var loader = new resLoader();
	loader.load([
		{ url:"//code.jquery.com/jquery-3.3.1.min.js", unless:window.jQuery, blocking:true }
	]);
</script>

In the example, jQuery will not be loaded a second time

Options

url - Resource urls to be loaded [array or string]

url: ["myScript.js","myScript-extra.js"]

async - Load the resource asynchronously [true/false]

async: false

Default: true

blocking - Load script in (render-)blocking mode [true/false]

blocking: true

Default: false

loadUnless - Load the resource unless expression is true

loadUnless: window.jQuery

unless - Shorthand for loadUnless

unless: window.jQuery

loadIf - Load the resource if expression is true

loadIf: window.jQuery

if - Shorthand for loadIf

if: window.jQuery

onComplete - Callback to be executed when everything is done (regardless of any conditional tests)

onComplete: function(){
	console.log("All done");
}

onLoad - Callback to be executed when a resource has beed loaded.

onLoad: function(){
	console.log("Resource has been loaded");
}

onLoadAll - Callback to be executed when all resources have beed loaded.

onLoadAll: function(){
	console.log("All resources are loaded");
}