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

async-loader-cdn

v1.2.1

Published

Load any CDN async

Downloads

271

Readme

Instalation

Using npm:

$ npm i async-loader-cdn

UPDATES

  • Change browser support to > 25%
  • Resolve fixture head.append to head.appendChild

What is AsyncLoaderCDN?

The AsyncLoaderCDN is a module that exposes a configurable class, where it has just one method: loader. This method is responsible for reading an informed list (either a fixed list or a firebase return), locating the item specified as a parameter in the method and uploading all necessary files. The load method returns a Promise when resolved it contains the global reference of what was loaded.

As some libraries are very extensive and large, including them in the project even with tree shaking, code splitting, in addition to requiring a more advanced configuration (just like in the case of webpack) can generate a final large file (like firebase library for example).

With AsyncLoaderCDN you can:

  • Significantly reduce your work and the size of the generated files.
  • Load resources at runtime and asynchronous mode according to the needs of the aplication state (load on demand)
  • Distribute several modes with just one instance, it’s no longer necessary other teams from the same ecosystem use their resources through the CDN or package managers.
  • When creating a new module, simply add it to the list to make it available for the entire ecosystem where it’s inserted.
  • Make the same modules available with different versions (new features for example), and the user can choose the version that suits at the moment.
  • If associated with a database (currently connected to Firebase, look at the exemples section) to save the list of modules, it’ll eliminate the need to generate a new release if you need to update CDN links or make a new feature available.

How to use

After installing, you can use in the following ways:

Import

import asyncLoader from 'async-loader-cdn';
const list = [
  {
    global: '_',
    name: 'lodash',
    version: '',
    files: ['https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.19/lodash.min.js'],
  },
];

// use async/await
const myLoaders = new asyncLoader(files);
myLoaders
  .load('lodash')
  .then((_) => {
    if (!_) return console.log('erro');
    console.log(_.VERSION);
  })
  .catch((err) => console.log(err));

Important

If you decide to use the list parameter, you need to send a list with this structure (contract):

const list = [
  {
    global: String, // global variable name of the module or project. Ex.: '$' if you want to load jQuery
    name: String, // name that asyncLoaderCDN will look for when the load method is called. Ex.: 'jQuery'
    version: <String|Int>, // if you need distribute multiple versions of the same module.
    files: [String],
  },
];

Examples

  • Usage with firebase here
  • Usage with list parameter here

How to contribute

To contribute to the project, fork this repository;

  • Create a branch with your feature;
  • Commit your changes;
  • Push to your branch;
  • Open a PR for the master;

After the PR is approved and the merge occurs, you can delete your branch.