i really wish browsers let you define your own handlers for import attributes.

like, imagine you could do something like this. it would let pretty much any language be used in the browser without a build step:

- strip types from typescript
- compile JSX/svelte/vue/etc into JS
- compile sass into CSS
- compile webgl/webgpu shaders?

there are probably problems i'm not thinking of. but it'd be super powerful!

// import.registerAttribute registers a handler that runs
// when a specific import attribute key matches the given string
import.registerAttribute("html", async response => {
  // `response` is a Response object with the result of the imported file
  const html = await response.text();

  // the return value is used as the imported object
  return new DOMParser().parseFromString(html, "text/html");
});

// setting the key `custom` to a registered string
// causes that handler to process the import
import hello from "./hello.html" with { custom: "html" };

document.documentElement.append(hello.children);
0

If you have a fediverse account, you can quote this note from your own instance. Search https://mastodon.social/users/jakelazaroff/statuses/115192289709513753 on your instance and quote it. (Note that quoting is not supported in Mastodon.)