Skip to main content
100%

JS in HTML

✓ Published0🌍 Public
JJaga-droid
Last edited Feb 14, 2023
Created on Feb 12, 2023
Forked from HTML Starter

This example demonstrates how JavaScript modules and dependencies are handled within an HTML page, highlighting the contrast between traditional script tags and ES6 module imports. It shows the console output of a string concatenated from variables exported across separate files, including `GetRekt.js` and `lmfao.js`, using named exports. The code uses ES6 `import` and `export` statements, which are bundled by Vizhub’s internal Rollup process when the file is named `index.js`. It visualizes the concept of topological sorting for script dependencies, though the actual rendering is limited to a plain HTML text display.

AI-generated description

Notes:-

  • Problem with using <src = 'script.js> is when you have multiple scripts. you would have to organize them in such a way that the dependencies, if any are satisfied(manually keep track of which script depends on another script). For example, if in {script.js,script1.js,script2.js} consider script.js where you want to refer to a global variable in script2.js, you want the order to be {script2.js,script.js,script1.js}. The algorithm which does this ordering is called "topological sorting".

  • ES6 Modules : In Vizhub platform, when you rename the js file to index.js, a bundle.js is created(only in vizhub) by means of "rollup" internally(within vizhub). A bundle is a file that combines many modules together.

  • D3 only uses named exports

  • can use a CDN to import d3

MIT Licensed

Similar vizzes