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

liteloader

v1.0.1

Published

async loads scripts and html imports while maintaing execution order

Downloads

112

Readme

liteloader-js

Conditionally loads scripts, HTML imports, imgs, and css in parallel while maintaining execution order for scripts. Can also be in-lined into index.html in the build process to cut a round-trip.

Note that for older browsers it expects to find the Promise polyfill in node_modules, if you are using an alternative polyfill or installing it via another route (like bower) you'll need to adjust the file path. Ditto for webcomponents.

Should be good to go for IE 9+.

##Example uses


// Lets say we have an application logic file, bizlogic.js with some dependencies:
Loader.load(
  '../node_modules/somelib.js',
  '../node_modules/otherlib.js'
).then(() => {
  // module code
});

// then lets say you have some event handlers to wire up that require the main file even though it
// doesn't export anything, in that file you'd just:
Loader.load(
  '../node_modules/somelib.js', // already imported, request deduped.
  '../node_modules/thirdLib.js',
  '../dist/bizlogic.js'
).then(() => {
  // attach handlers.
});

// if an asset fails to load the Promise will reject, allowing you to do your own error handling.
// But this presents a catch-22: you are using the loader to load your error handling code!
// liteloader has its own error modal dialog box for you to use:

Loader.load('doesntexist.js').catch(Loader.showError);

Couple of things to note:

  • This module uses a Promise-based API. It will attempt to load the polyfill if it doesn't detect Promise so no need to include it on every page.
  • Ditto for webcomponents.
  • You have to use global namespaces to get a handle on module output.
  • Requests are cached, requests for the same asset (identical URLs) do not trigger network calls.
  • For images you get a Promise of the img tag but no other action is taken, for all other assets you get a Promise of the element that resolves when its onload fires (scripts, css and HTML imports are injected into the document for you).

While not nearly as full-featured as some other loaders and relies on global namespace vars, this one is simple and lean at 6kb unzipped.

##To run the tests:

Tests are run via jasmine. Type 'make serve' in the project directory and point your browser at http://localhost:8080/.