Can't understand the difference between the two examples that I just read at the end of the Deno manual section on the deno bundle
command:
Bundles can also be loaded in the web browser. The bundle is a self-contained ES module, and so the attribute of type must be set to "module". For example:
<script type="module" src="website.bundle.js"></script>
Or you could import it into another ES module to consume:
<script type="module"> import * as website from "website.bundle.js"; </script>
I was under the impression that both forms achieve the same effect (i.e., "fetched and executed immediately, before the browser continues to parse the page"), and the latter is used when a script follows or one wants to narrow down what is imported (e.g., as seen in this answer).
Section 16.6.1.2 Modules of the Exploring ES6 book appears to agree with this assessment.
Reddit thread Difference Es6 import module vs script src="" also seems to confirm this: "Instead of dumping an entire library into your global scope you an instead only include what you need and actually use."
This may be considered a duplicate of other questions (see bottom for the list) but those answers didn't help me much, and the ancillary sources also didn't seem to reveal if my assumption is correct. (On the other hand, it is more than possible that I overlooked something obvious and would have to work on my reading comprehension skills...)
- Load javascript as an ES6 module OR via a script tag in the page (tangentially related)
- What is the difference between a script tag with src and a script tag that requires a module? (looked promising but not about ES6 modules...)
- Classic scripts v/s module scripts in Javascript
- WHATWG: Adding JavaScript modules to the web platform
- Import js from script tag in HTML file. Possible?
- What is the difference between importing js library or reference it in html <script> tag (not about ES6 modules)
- Should I reference files in a `script` tag when using ES6 modules in a browser
- ES6 import vs <script src> in html