load-script

Dynamic browser script loading with a simple callback-based API.

Library
npm
v2.0.0
149stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
36/100Needs Attention
Development Activity0
Maintenance20
Community52
Maturity60
Momentum12

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
62/100Good
Architecture60
Code Quality62
Innovation55
Learning Curve90

load-script is a minimal browser utility for loading external JavaScript files at runtime. It appends a script node to the document head and invokes a callback when the script finishes loading or fails, giving you programmatic control over on-demand code loading.

With support for async toggling, custom attributes, charset, and inline text, it wraps the boilerplate of DOM script injection — including legacy IE readystate handling — behind a single function call.

What You Get

  • A single load(url, opts, cb) function for dynamic script injection
  • Callback notification on both successful load and load failure
  • Options for async, type, charset, custom attributes, and inline text
  • Cross-browser onload handling including legacy IE readystatechange fallback

Common Use Cases

  • Lazy-loading third-party widgets or SDKs only when needed
  • Deferring non-critical scripts to improve initial page load
  • Conditionally injecting analytics or payment provider scripts at runtime

Under The Hood

Architecture - The library is a single index.js module exporting one function. It grabs document.head, creates a script element, applies options (type, charset, async, custom attrs, inline text), attaches onload/onerror handlers via a stdOnEnd/ieOnEnd split for cross-browser completion detection, then appends the node to the head. Tech Stack - Plain ES5 JavaScript with zero runtime dependencies; ships a hand-written index.d.ts for TypeScript consumers. Tests run through zuul. Code Quality - Compact and readable at under 60 lines, with a browser test suite in test/. The IE fallback paths add legacy complexity but are clearly commented. API Design - Minimal and ergonomic: one function, optional options and callback with sensible defaults, so the simplest call is load(url, cb).

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search