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

resource-pipe-js

v1.0.1

Published

A tiny library that loads external scripts and styles sequentially (without any external dependencies)

Downloads

4

Readme

PipeJS

PipeJS is a tinny library that allows developers to fetch and load external scripts and styles asynchronously but at the same time, sequentially according to the specific order.

Note this library is designed for browser only!

Why PipeJS?

Websites nowadays often depend on many different external scripts and styles, which usually requires lots of times to load them all. So developers may want to load the resources separately and asynchronously but according to the dependencies and orders among them. This usually involves many dom manipulating methods and ajax loads and waits to finish them all! So PipeJS is designed to provide a simplified means to fulfill the needs as easy and intuitive as possible. And at the same time, it will be better to acheive it without any dependency.

Installation

Simply add the following line into <head> tag

<script src="https://cdn.rawgit.com/JCloudYu/pipejs/master/pipe.min.js"></script>

Or you can download the script from here and add to your code stash~

How to use?

This library registers a function named pipe onto the window object. It's the sole function the developer should know to load resources. The pipe api accept an array of resource descriptors.

Resource Descriptor

Resource descriptors is an object contains following properties | name | type | required | default | description | |:----------|:-----:|:---:|:----:|:--------------| | path | String | Y | | The path of the external resource | | type | 'js' or 'css' | N | 'js' | The type of the resource | | cache | Boolean | N | true | Whether the resource will be cached by the browser | | important | Boolean | N | true | True will make the whole reading process stop if the resource is not loaded | | modulize | Boolean | N | false | A special flag that will read the script as module | | overwrites | Object | N | {} | The variable to be overwritten when the resource is read in module mode |

Moreover, a resource descriptor can simply be a string, which is equivalent to the following object resource descriptor.

{
    path: "The resource string...",
    type: "js",
    cache: false,
    important: true,
    modulize: false,
    overwrites: {}
}

The sequence separator

If a resource descriptor is neither a string nor an object, then the descriptor is treated as a sequence separator. Resources between the separators will be treated as different groups. Within a groupped resources, the resources will be loaded asynchronously and the order among them will not be guaranteed. However, the groups will be guaranteed to be loaded sequentially.

A function can also be a sequence separator. A separator function will be guarateed to be invoked after the prior resources are loaded completely. This is handy for developers to perform some procedural actions between the load of the resources.

Example

await pipe([
    'http://code.jquery.com/jquery-3.3.1.min.js',    
    ()=>{
        console.log( "Jquery is loaded!" );
        console.log( "From now on, the jQuery is guaranteed to be available!" );
    },
    
    { path:'http://momentjs.com/downloads/moment.min.js', cache:false },
    // This script will be failed but the whole loading process will not be stopped!
	{ path:'http://momentjs.com/downloads/moment222.min.js', cache:false, important:false },

    //A separator the guarantee the super-fast.js is loaded after the load of moment.min.js and pump2.min.js
    null,
    
    './super-fast.js'
])
// The promise returned by the pipe api will contain a pipe method
// This allows developers to chain up the load process
.pipe([
    { path:'./super-slow.js', modulize:true, cache:true, overwrites:{}},
    { type:'css', path:'./style.css' },
    { type:'css', path:'./style2.css', important:false },
	
    // The following line will make the reading process stopped and the promise returned will be rejected!
    //{ type:'css', path:'http://momentjs.com/downloads/moment222.min.js' },
    { type:'css', path:'./style-final.css' }
]);

console.log( "Everything is done! Now you can use anything freely!" );