liveBook · Manning

Module script

As explained in Web Components in Action

An HTML script-loading mode that interprets a script as an ECMAScript module and enables module loading semantics.

Add `type="module"` to an HTML `<script>` to enable module loading. The script can import a component, whose imports load its dependencies, so the page can reference just the top-level app component. Use a local web server: loading modules directly from the filesystem may be blocked. section 5.2

Listing 5.5. A minimal application HTML file for our Web Harp demo
<html>
   <head>
       <title>Web Harp</title>
       <script type="module"                        #1
               src="./components/app/app.js">
       </script>
       <link href="csshake.min.css"                 #2
             type="text/css" rel="stylesheet">
       <link href="main.css"                        #3
             type="text/css" rel="stylesheet">
   </head>
   <body>
       <webharp-app strings="8"></webharp-app>
   </body>
</html>

Minimal Web Harp HTML page with a module script that loads the app component. section 5.2

How Web Components in Action covers it

How deep it goes
Explains how the module type enables imports across dependencies, without detailing module internals.
Examples
Demonstrates a Web Harp page that loads an app component and its nested component dependencies.
What you can do after
Build it from scratch by loading an app component and its imports through an HTML module script.
How it connects
Connects HTML script elements with ECMAScript modules, import, and Web Components.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Web Components in Action. The section links point to the parts of the book it draws on.