# dimport [![Build Status](https://badgen.now.sh/travis/lukeed/dimport)](https://travis-ci.org/lukeed/dimport) > Run ES Module syntax (`import`, `import()`, and `export`) in any browser — even IE! At its core, `dimport` is a polyfill for ES Module syntax, including [dynamic imports](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#Dynamic_Imports)!
And with it, you can serve modern ESM-driven application files to any browser. While browsers _are_ increasing support for JavaScript modules natively, the current landscape is not easy to navigate.
For example, many browsers _do support_ ESM syntax (aka, `import` and `export`) within ` ``` In the sample above, a browser will automatically choose which script `type` to parse.
This means the two scripts can live side-by-side without loading your application twice!
Finally, the _same_ application file (`bundle.js`) can be used, despite the `module`-vs-`nomodule` choice. You will also notice that the scripts have a `data-main=""` attribute.
This the path to _your application_ or _your ESM-containing file_ you wish to load. Once `dimport` has loaded, it circles back and see that its ` ``` Finally, `dimport` is available for programmatic use and/or usable _within_ your bundle (via Webpack or Rollup) ``` $ npm install --save dimport ``` ```js import dimport from 'dimport'; // or, without bundling import dimport from 'https://unpkg.com/dimport?module'; // Pass in URLs or file paths // ~> like `import()` usage dimport('./foo.js').then(...); ``` ## API – Programmatic ### dimport(url) Returns: `Promise` Returns a Promise containing the module. #### url Type: `String` The URL of the script to import. > **Note:** Will be transformed into a full URL if not already – see [`new URL()`](https://developer.mozilla.org/en-US/docs/Web/API/URL/URL#Examples) ## Browser Support The `dimport` columns yield support for **both** static and dynamic imports. > **Important:** Chart represents ESM syntax only!
Not indicative of ES2015+ syntax usage within your app. | Browser | `import`
native | `import()`
native | dimport
module | dimport
nomodule | dimport
legacy | |---------|--------------------|----------------------|-------------------|---------------------|-------------------| | Chrome | 61 | 63 | 61 | 42 | :+1:* | | Safari | 10.1 | 11.1 | 10.1 | 10.1 | :+1:* | | Firefox | 60 | 67 | 60 | 39 | :+1:* | | Edge | 16 | :x: | 16 | 14 | :+1:* | | IE | :x: | :x: | :x: | :x: | 7 * | * _Indicates support with `Promise` polyfill supplied_ ## Prior Art * [`dynamic-import-ponyfill`](https://www.npmjs.com/package/dynamic-import-ponyfill) – The "first version" of `dimport` – now deprecated. * [`shimport`](https://github.com/Rich-Harris/shimport) – Patient zero. Similar to "nomodule" mode. Made it "okay" to rewrite files on the fly. ## License MIT © [Luke Edwards](https://lukeed.com)