Thanks heaps... this is super handy... I'm glad you have started teaching Web Components. I've been using them for years and recently have been experimenting with using them for SSR and have played with Qwik style resumable/ event driven JS loading.... This style dynamic import on a Custom Element would work really nicely with just in time Javacript...
Thanks! This is something which I was not aware of. However, I've a question, since side effect imports, imports the whole file, do they cause namespace collision?
Thanks Steve. I appreciate your videos. If the module contains a function with parameters, how to call this function from my "main.js" I can't figure it out.
What if i write smth like "import 'someFolder/subFolder'", how does it know which file to run? does it look for an index.js file? could not find documentation for it
You can split your own code. That new code has its own scope too. It is protected from other scripts. Additionally you can import and automatically run modules written by someone else.
@@SteveGriffith-Prof3ssorSt3v3 So I just checked the network tab of my browser, using @import is not the same as if I wrote all my code inside one 'main.js' file. If I use @import 'utils.js' in my 'main.js' file, the browser will load both files (utils.js and main.js), I thought the @import keyword would put all the code from 'utils.js' into my 'main.js' file. Isn't it actually bad that now -with the @import key- the browser has to load 2 files instead of 1?
Modules are deferred by default. So, they get read and executed after the DOM is parsed. The scripts and modules are all fetched and executed in the order that they appear. These are both deferred and then executed after the DOM is parsed.
@@SteveGriffith-Prof3ssorSt3v3 and is posible to modify this default? So I prefer to use ESM over iife, but also I want that the user can interact meanwhile the user see a "suspense" during html streaming. Is it that possible? 😬 Thanks anyway!!
so, just to review, if my modules don't return anything like a FUNCTION does, and, they just execute some code like a METHOD does.. you don't have to "export" anything and still you can import that module to "SHOW" some content for example. Am I right?
thank you steve
Thanks heaps... this is super handy... I'm glad you have started teaching Web Components.
I've been using them for years and recently have been experimenting with using them for SSR and have played with Qwik style resumable/ event driven JS loading....
This style dynamic import on a Custom Element would work really nicely with just in time Javacript...
Thanks for adding interesting information in my knowledge
Thanks! This is something which I was not aware of.
However, I've a question, since side effect imports, imports the whole file, do they cause namespace collision?
With side effects you are not actually importing anything from the module. You are running the side effect code only
Thanks Steve. I appreciate your videos.
If the module contains a function with parameters, how to call this function from my "main.js"
I can't figure it out.
If you want to call a function then you need to export the function from the file and import the function into main.js
Thanks Steve
My problem was with parameters.
I almost found the solution.
thank you sir for this knowledgeable video.
Thanks so much))
What if i write smth like "import 'someFolder/subFolder'", how does it know which file to run? does it look for an index.js file? could not find documentation for it
@@TheY3nX you have to add the specific filename in full
So it is the same as if I would write all the code in main.js file right? The benefit is that I can split my code
You can split your own code. That new code has its own scope too. It is protected from other scripts.
Additionally you can import and automatically run modules written by someone else.
@@SteveGriffith-Prof3ssorSt3v3 So I just checked the network tab of my browser, using @import is not the same as if I wrote all my code inside one 'main.js' file. If I use @import 'utils.js' in my 'main.js' file, the browser will load both files (utils.js and main.js), I thought the @import keyword would put all the code from 'utils.js' into my 'main.js' file. Isn't it actually bad that now -with the @import key- the browser has to load 2 files instead of 1?
Is there some way to run these esmodule scripts during HTML streaming time? Or is required iife without esm?
Modules are deferred by default. So, they get read and executed after the DOM is parsed. The scripts and modules are all fetched and executed in the order that they appear.
These are both deferred and then executed after the DOM is parsed.
@@SteveGriffith-Prof3ssorSt3v3 and is posible to modify this default? So I prefer to use ESM over iife, but also I want that the user can interact meanwhile the user see a "suspense" during html streaming. Is it that possible? 😬 Thanks anyway!!
so, just to review, if my modules don't return anything like a FUNCTION does, and, they just execute some code like a METHOD does.. you don't have to "export" anything and still you can import that module to "SHOW" some content for example.
Am I right?
yes!