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 🙏

© 2026 – Pkg Stats / Ryan Hefner

minimal-script-loader

v1.0.1

Published

Minimal browser library to import JS and CSS and to use XHR easily.

Readme

minimal-script-loader

Minimal browser library to import JS and CSS and to use XHR easily.

Installation

Install npm package:

~$ npm install --save minimal-script-loader

Import the package:

a. Via script tag:

<script src="node_modules/minimal-script-loader/dist/script-loader.min.js"></script>

If so, the library will be available at ScriptLoader global variable.

b. Via browserify:

const ScriptLoader = require("minimal-script-loader");

Once done this, ScriptLoader is available in the scope.

Examples

A demo of each type of call (js, css and xhr) is shown below.

Load a external JS file:

ScriptLoader.js("https://cdnjs.cloudflare.com/ajax/libs/qunit/2.8.0/qunit.js")
 .then(function() {
   console.log("QUnit was loaded successfully!");
 })
 .catch(function() {
   console.log("QUnit could not be loaded!");
 });

Load a external CSS file:

ScriptLoader.css("https://cdnjs.cloudflare.com/ajax/libs/qunit/2.8.0/qunit.css")
 .then(function() {
   console.log("QUnit (stylesheet) was loaded successfully!");
 })
 .catch(function() {
   console.log("QUnit (stylesheet) could not be loaded!");
 });

Load a external XHR file:

ScriptLoader.xhr({
   url: "/",
   method: "GET",
   headers: {"Custom-Headers":"Yes, we can too"},
   json: false,
   timeout: 5000
 })
 .then(function() {
   console.log("Self-call made successfully!");
 })
 .catch(function() {
   console.log("Self-call could not be made!");
 });

API Reference


class ScriptLoader

Type: class

Extends: Object

Description: The whole API is this class.


static method ScriptLoader.js(url)

Type: static class method

Parameter: {String} url. URL to fetch the script from.

Returns: {Promise} promise. A Promise that will be resolved/rejected once the script is loaded/failed.

Description: This method creates a script tag, sets the src field and injects it into the DOM (document.body). It sets the onload and onerror into the request using the values provided to the Promise.


static method ScriptLoader.css(url)

Type: static class method

Parameter: {String} url. URL to fetch the css stylesheet from.

Returns: {Promise} promise. A Promise that will be resolved/rejected once the stylesheet is loaded/failed.

Description: This method creates a link tag, sets the rel, type and href and injects it into the DOM (document.head). The callback called is always success, and immediately. But this is maintained in order to standarize the API (maybe some day stylesheet callbacks are a valid strategy).


static method ScriptLoader.xhr(options)

Type: static class method

Parameter: {Object} options.

Returns: {Promise} promise. A Promise that will be resolved/rejected once the XHR call is loaded/failed.

Description: This method is exactly this function. Refer to it for more information.

Commands

The available commands of the project are displayed as npm run ~ commands, so you can check them in package.json#scripts.

Conclusion

It is important to have a handy way to easily import data externally in your web pages, scripts, apps, etc...

You will have to do it somehow.