finds.dev← search

// the find

addyosmani/basket.js

★ 3,350 · JavaScript · MIT · updated Mar 2025

A script and resource loader for caching & loading files with localStorage

Basket.js loads external scripts and caches their source in localStorage so repeat page loads skip the network round-trip, with a promise-based require/remove/clear API and version-based invalidation. It's aimed at old-school multi-page sites loading third-party scripts, not at anyone using a bundler with code-splitting and long-lived HTTP caching already handling this.

The API surface is small and predictable — require/remove/clear/get map cleanly onto what you'd expect, and options like expire, unique, and skipCache cover the real edge cases of cache invalidation. The addHandler system is a nice touch, letting you cache CSS or other text assets through the same pipeline instead of just JS. The test suite actually exercises failure modes (fail-script.js, execute:false, large payloads) rather than just the happy path, and the recent push adds ESM/CJS dual output via a Vite build so it isn't stuck as a UMD-only relic.

localStorage reads/writes are synchronous and block the main thread, and the ~5-10MB quota means this falls over fast if you're caching more than a couple of libraries — the exact problem HTTP caching and Service Workers already solve without the blocking I/O. Storing raw script text and re-injecting it for execution has no subresource-integrity or hash check anywhere in the README, so a compromised CDN response gets silently cached and re-run on every subsequent visit. It also doesn't play well with a CSP that disallows inline script execution, which is increasingly the default. Given HTTP/2, cache-control headers, and native ES module imports handle this use case natively in any modern stack, the realistic audience for this in 2026 is narrow — legacy non-bundled sites, not new projects.

View on GitHub →

// want more like this?

We dig through GitHub every week and send a few repos picked for what you actually care about — each with an honest take like this one.

Get finds in your inbox → Search again →