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 🙏

© 2025 – Pkg Stats / Ryan Hefner

basket.js

v1.0.0

Published

A script-loader that handles caching scripts in localStorage where supported

Readme

Basket.js

Basket.js is a script loader that efficiently caches scripts in localStorage for improved page load times.

Features

  • Script Caching: Automatically caches loaded scripts in localStorage
  • Version Control: Built-in support for script versioning
  • Expiration Control: Set expiration times for cached scripts
  • Promise-based API: Modern Promise-based interface
  • Custom Handlers: Support for different content types
  • Modular: ESM and CommonJS support

Installation

npm install basket.js

Usage

ES Modules

import basket from 'basket.js';

// Load a single script
basket.require({ url: 'jquery.min.js' })
  .then(() => {
    console.log('jQuery loaded!');
  });

// Load multiple scripts
basket.require(
  { url: 'jquery.min.js' },
  { url: 'backbone.min.js' }
).then(() => {
  console.log('Libraries loaded!');
});

// Advanced usage with options
basket.require({
  url: 'my-script.js',
  key: 'custom-key',        // Custom key for storage
  expire: 24,               // Expires in 24 hours
  execute: false,           // Don't execute after loading
  unique: '1.0.0',         // Version control
  skipCache: false,        // Use cache when available
  live: false              // Always fetch fresh copy
});

CommonJS

const basket = require('basket.js');

API

basket.require(options)

Loads one or more scripts with specified options.

Options:

  • url (String): URL of the script to load
  • key (String): Custom storage key (defaults to URL)
  • expire (Number): Hours until expiration (default: 5000)
  • execute (Boolean): Whether to execute the script (default: true)
  • unique (String/Number): Version identifier
  • skipCache (Boolean): Skip localStorage caching
  • live (Boolean): Always fetch from network

Returns a Promise that resolves when all scripts are loaded.

basket.remove(key)

Removes a script from localStorage.

basket.remove('jquery');

basket.clear([expired])

Clears all scripts from localStorage. If expired is true, only removes expired scripts.

// Clear all scripts
basket.clear();

// Clear only expired scripts
basket.clear(true);

basket.get(key)

Retrieves a script's cached data.

const scriptData = basket.get('jquery');

basket.addHandler(type, handler)

Add a custom handler for specific content types.

basket.addHandler('text/css', (obj) => {
  const style = document.createElement('style');
  style.textContent = obj.data;
  document.head.appendChild(style);
});

Development

# Install dependencies
npm install

# Run development server
npm run dev

# Build for production
npm run build

# Run tests
npm test

Browser Support

Basket.js requires browsers with:

  • localStorage support
  • Promise support (or use a polyfill)
  • Modern JavaScript features (or use appropriate build tools)

License

MIT License

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request