MDN self-hosted library · e01.org

Import attributes

Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.

js
import data from "https://example.com/data.json";
js
import data from "https://example.com/data.json" with { type: "json" };
js
import data from "https://example.com/data.json" with { type: "json" };
js
import exampleStyles from "https://example.com/example_styles.css" with { type: "css" };

document.adoptedStyleSheets.push(exampleStyles);
js
import text from "https://example.com/file.txt" with { type: "text" };
html
<!doctype html>
<html lang="en-US">
  <head>
    <meta charset="utf-8" />
    <script type="module">
      import data from "./data.json" with { type: "json" };

      const p = document.createElement("p");
      p.textContent = `name: ${data.name}`;
      document.body.appendChild(p);
    </script>
  </head>
  <body></body>
</html>
js
const data = await import("./data.json", {
  with: { type: "json" },
});