Skip to content

Instantly share code, notes, and snippets.

@walkermatt
Last active January 16, 2025 09:57
Show Gist options
  • Save walkermatt/01e83ea99a1ea0f7ed7af9d281643df8 to your computer and use it in GitHub Desktop.
Save walkermatt/01e83ea99a1ea0f7ed7af9d281643df8 to your computer and use it in GitHub Desktop.
Load ES module in a html page

Load ES module in a html page

Place the files in a directory. Serve the files via a web server such as the built-in python http server. Open index.html in your browser, open the DevTools Console and reload.

class App {
constructor(options) {
this.name = options.name;
}
getGreeting() {
return `Hi ${this.name}!`;
}
}
export { App };
<!DOCTYPE html>
<html lang="en-GB">
<head>
<meta charset="utf-8" />
<title>Load Class from ES module</title>
<link rel="icon" href="data:;base64,iVBORw0KGgo=" />
</head>
<body>
<script type="module">
import { App } from './app.js';
const app = new App({
name: 'Domna',
});
console.log(app.getGreeting());
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment