Skip to content

Commit

Permalink
deprecate: dynamic import, import.meta, edge polyfills (#450)
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford authored Jan 13, 2025
1 parent 0f31019 commit c4b4334
Show file tree
Hide file tree
Showing 10 changed files with 117 additions and 173 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ jobs:
test-firefox:
runs-on: windows-latest
strategy:
fail-fast: false
matrix:
firefox: [
'65.0', # (60 = modules support, but not working)
'67.0', # import(), import.meta
'89.0', # top-level await
'108.0',
Expand Down Expand Up @@ -55,6 +55,7 @@ jobs:
test-chrome:
runs-on: windows-latest
strategy:
fail-fast: false
matrix:
chrome: [
'695071', # ~September 2019
Expand Down
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

Polyfills import maps and other ES Modules features on top of the baseline native ESM support in browsers.

With import maps now supported by all major browsers, ES Module Shims entirely bypasses processing for the [91% of users](https://caniuse.com/import-maps) with native import maps support.
With import maps now supported by all major browsers, ES Module Shims entirely bypasses processing for the [94% of users](https://caniuse.com/import-maps) with native import maps support.

For the remaining users, the highly performant (see [benchmarks](#benchmarks)) production and [CSP-compatible](#csp-support) shim kicks in to rewrite module specifiers driven by the [Web Assembly ES Module Lexer](https://github.com/guybedford/es-module-lexer).
For the remaining ~4% of users, the highly performant (see [benchmarks](#benchmarks)) production and [CSP-compatible](#csp-support) shim kicks in to rewrite module specifiers driven by the [Web Assembly ES Module Lexer](https://github.com/guybedford/es-module-lexer).

The following modules features are polyfilled:

Expand Down Expand Up @@ -210,8 +210,8 @@ ES Module Shims is designed for production performance. A [comprehensive benchma

Benchmark summary:

* [ES Module Shims Chrome Passthrough](bench/README.md#chrome-passthrough-performance) (for [72% of users](https://caniuse.com/import-maps)) results in ~5ms extra initialization time over native for ES Module Shims fetching, execution and initialization, and on a slow connection the additional non-blocking bandwidth cost of its 10KB compressed download as expected.
* [ES Module Shims Polyfilling](bench/README.md#native-v-polyfill-performance) (for the remaining [28% of users](https://caniuse.com/import-maps)) is on average 1.4x - 1.5x slower than native module loading, and up to 1.8x slower on slow networks (most likely due to the browser preloader), both for cached and uncached loads, and this result scales linearly up to 10MB and 20k modules loaded executing on the fastest connection in just over 2 seconds in Firefox.
* [ES Module Shims Chrome Passthrough](bench/README.md#chrome-passthrough-performance) (for [94% of users](https://caniuse.com/import-maps)) results in ~5ms extra initialization time over native for ES Module Shims fetching, execution and initialization, and on a slow connection the additional non-blocking bandwidth cost of its 10KB compressed download as expected.
* [ES Module Shims Polyfilling](bench/README.md#native-v-polyfill-performance) (for the remaining [3% of users](https://caniuse.com/import-maps)) is on average 1.4x - 1.5x slower than native module loading, and up to 1.8x slower on slow networks (most likely due to the browser preloader), both for cached and uncached loads, and this result scales linearly up to 10MB and 20k modules loaded executing on the fastest connection in just over 2 seconds in Firefox.
* [Very large import maps](bench/README.md#large-import-maps-performance) (100s of entries) cost only a few extra milliseconds upfront for the additional loading cost.

## Features
Expand All @@ -222,7 +222,7 @@ Works in all browsers with [baseline ES module support](https://caniuse.com/#fea

Browser Compatibility on baseline ES modules support **with** ES Module Shims:

| ES Modules Features | Chrome (71+) | Firefox (60+) | Safari (10.1+) |
| ES Modules Features | Chrome (63+) | Firefox (67+) | Safari (11.1+) |
| ----------------------------------------------- | ------------------------------------ | ------------------------------------ | ------------------------------------ |
| [modulepreload](#modulepreload) | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
| [Import Maps](#import-maps) | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
Expand Down
53 changes: 0 additions & 53 deletions src/dynamic-import.js

This file was deleted.

4 changes: 2 additions & 2 deletions src/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ export const hasDocument = typeof document !== 'undefined';

export const noop = () => {};

export const dynamicImport = (u, errUrl) => import(u);

const optionsScript = hasDocument ? document.querySelector('script[type=esms-options]') : undefined;

export const esmsInitOptions = optionsScript ? JSON.parse(optionsScript.innerHTML) : {};
Expand Down Expand Up @@ -50,8 +52,6 @@ export const onpolyfill =
console.log(`%c^^ Module error above is polyfilled and can be ignored ^^`, 'font-weight:900;color:#391');
};

export const edge = !navigator.userAgentData && !!navigator.userAgent.match(/Edge\/\d+\.\d+/);

export const baseUrl =
hasDocument ?
document.baseURI
Expand Down
Loading

0 comments on commit c4b4334

Please sign in to comment.