Exporting modules in JS

So far in the course we have been doing server-side rendering for our projects with Node, but this week we are making single-page applications with client-side rendering.

Loading lots of <script> tags on our singular HTML file can slow the application down because each time a new script is encountered an HTTP request is made, and this blocks the rendering of the page.

Instead we can load our scripts as ES Modules, and the client will follow the import paths and execute each module once. We can do this by adding type="module" to the script tags on our HTML file.

<script type="module" src="app.js"></script>