Skip to content

Commit

Permalink
Rephrase instructions
Browse files Browse the repository at this point in the history
Better served as main lesson text rather than a note box
  • Loading branch information
MaoShizhong committed Sep 6, 2024
1 parent 249f3d5 commit 4c6e3a9
Showing 1 changed file with 1 addition and 11 deletions.
12 changes: 1 addition & 11 deletions javascript/organizing_your_javascript_code/es6_modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,17 +214,7 @@ two.js <-------------- one.js <-------------- three.js

Note that we only needed the one script tag, as the browser will handle the additional file dependencies for us. We also did not need to add the `defer` attribute, as `type="module"` will automatically defer script execution for us.

If you had coded along with the IIFE example at the start of the lesson, try rewriting the JavaScript to use `import` and `export`, and link only the entry point as a module script.

<div class="lesson-note lesson-note--warning" markdown="1">

#### Opening ES6 modules locally in the browser

Due to security restrictions with the `file://` protocol, if you try to open an HTML file with module scripts directly in the browser (e.g. running `google-chrome index.html` in the terminal or similar), you will be greeted with a CORS error.

ES6 modules need to be served via a server. For now, if you haven't been using it already, you should use Visual Studio Code's [Live Server extension](https://marketplace.visualstudio.com/items?itemName=ritwickdey.LiveServer).

</div>
If you had coded along with the IIFE example at the start of the lesson, try rewriting the JavaScript to use `import` and `export`, and link only the entry point as a module script. Due to browser security reasons, ES6 modules cannot be loaded if you open the HTML file directly in the browser, so make sure you use Visual Studio Code's [Live Server extension](https://marketplace.visualstudio.com/items?itemName=ritwickdey.LiveServer) if you aren't already.

### CommonJS

Expand Down

0 comments on commit 4c6e3a9

Please sign in to comment.