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

@malko/l.js

v0.2.2

Published

another simple/tiny javascript/css loader

Downloads

1,153

Readme

l.js is another simple/tiny javascript/css loader

FOSSA Status

features

  • compatible with all ECMASCRIPT 5.1 browsers (Warning for old users this is a breaking change on supporting long time deprecated browsers)
  • parallel script / css loading
  • callback after script loading (css support callback too but are executed imediately)
  • tiny only 2ko uglifyed, less than 1.1ko gziped (at least for latest revision)
  • may load in order to preserve dependencies
  • support aliases for simpler calling
  • on demand loading
  • only one script tag required
  • clear syntax (to use not in the source code :) )
  • successive load of same file will load it once but execute all callbacks associated
  • can dumbly check already inserted tags at load time
  • may use a fallback url on error (only for js files and with error events compatible browsers)
  • may register error handlers (only for js files and with error events compatible browsers)
  • can load javascripts modules

examples

loading ljs and another libs with one single tag

<script src="l.js">
	ljs.load('myLib.js',function(){ /* your callback here */});
</script>

or using jsdeliver CDN:

<script src="https://cdn.jsdelivr.net/gh/malko/l.js@latest/l.min.js">
	ljs.load('myLib.js',function(){ /* your callback here */});
</script>

If you're looking for the npm package, you should search for l.js-loader npm install @malko/l.js

loading some scripts in parallel others in order

<script src="l.js">
	ljs
		.load('myLib.js')
		.load('myRequiredLib.js','myDependentLib.js',function(){ /* your callback here */})
	;
</script>

second load will be executed in parallel of first load but myDependentLib.js won't load before myRequireLib.js is loaded

<script src="l.js">
	ljs.load(['myLib.js','myRequiredLib.js'],'myDependentLib.js',function(){ /* your callback here */});
</script>

this will load myLib.js and myRequiredLib.js in parrallel and wait for them before loading myDependentLib.js

using some aliases for simpler loading

<script src="l.js?checkLoaded"> // <- adding checkLoaded to the url will dumbly check already inserted script/link tags
	ljs
		.addAliases({
			jQuery:'http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js#jqueryId' // <- script tag will have attribute id=jqueryId
			,ui:[
				'jQuery'
				,'https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js'
				,'myUITheme.css'
			]
		})
		.load('ui',function(){
			/* work with both jquery and jquery-ui here */
		})
	;
</script>

define a fallback url

l.js also support a fallback url for javascript files in case you want to try to get the resource from another location on loading failure You can define this fallback url parameter like you define ids. The difference is you will prefix with #= instead of # alone

<script src="l.js">
	ljs.load('http://domain.com/myLib.js#=/myfallback.js#myid',function(){
		/*
			generated script tag will have myid as id and will try to load /myfallback.js if it fail to load http://domain.com/myLib.js
		*/
	});
</script>

register an error handler

<script src="l.js">
	ljs
		.load('missingFile.js',function(){ /* your callback here */})
		.onError(function(url) {
			console.log('error loading', url); // <- will print "error loading missingFile.js"
		})
	;
</script>

load a js module

As a default l.js load js scripts with their type attribute set to text/javascript. To set type to module instead, simply prefix the url with module:

<script src="l.js">
    ljs.load('module:myModuleLib.js',function(){ /* your callback here */});
</script>

this piece of code is dual licensed under MIT / GPL Hope this help, code review, suggestions, bug reports are welcome and appreciated.

License

FOSSA Status