universal-url-lite

A smaller Universal WHATWG URL, for Browserify/etc.

Usage no npm install needed!

<script type="module">
  import universalUrlLite from 'https://cdn.skypack.dev/universal-url-lite';
</script>

README

universal-url-lite NPM Version Build Status Dependency Monitor

A smaller Universal WHATWG URL, for Browserify/etc.

The universal-url package bundles to 392kB (99kB gzipped). This package exists to compile the same to a smaller file size via custom optimizations.

This package is not meant to be required/imported directly. It should be added to your browser build process as an alias.

Installation

Node.js >= 6 is required. To install, type this at the command line:

npm install universal-url-lite

Default Shim File Size File Size

Usage:

"browser": {
  "universal-url": "universal-url-lite"
}

File size optimizations have been made, particularly the near-complete exclusion of the TR46 implementation. Functionality is essentially the same as the universal-url package, with the exception of IDNA validation and normalization. If a URL contains a hostname with any of the ~4500 Unicode characters requiring a specific casefold, comparison will produce false negatives. Consider this example:

const url1 = 'http://ㅼㅼㅼ/';
const url2 = 'http://ᄯᄯᄯ/';

if (new URL(url1).hostname !== new URL(url2).hostname) {
    // This is wrong
}

With invalid IDNAs passing through without error, you will instead need to rely on errors produced by XMLHttpRequest/fetch to know that such URLs are unreachable.

Note: You will need to exclude this browser shim from bundle parsing since it has already been compiled. Browserify has the --noparse CLI option and Webpack has the noParse package.json key.

browserify in.js --outfile=out.js --noparse='/project/node_modules/universal-url-lite/lite.js'

"Native" Shim File Size

This actually includes no shim at all for browser builds. Only the latest browsers will be supported.

Usage:

"browser": {
  "universal-url": "universal-url-lite/native"
}