Learn Dynamic Module Imports In 11 Minutes

  Рет қаралды 139,644

Web Dev Simplified

Web Dev Simplified

Күн бұрын

JavaScript Simplified Course: javascriptsimplified.com
Most people are familiar with standard ES6 module imports in JavaScript, but did you know that you can also do dynamic module imports as well. These imports are perfect for code splitting, and speeding up your page load speeds. In this video I will explain everything you need to know about dynamic module imports with in depth real world examples.
📚 Materials/References:
JavaScript Simplified Course: javascriptsimplified.com
Dynamic Module Imports Article: blog.webdevsimplified.com/202...
Destructuring Video: • Why Is Array/Object De...
Destructuring Article: blog.webdevsimplified.com/202...
Async Await Video: • JavaScript Async Await
🌎 Find Me Here:
My Blog: blog.webdevsimplified.com
My Courses: courses.webdevsimplified.com
Patreon: / webdevsimplified
Twitter: / devsimplified
Discord: / discord
GitHub: github.com/WebDevSimplified
CodePen: codepen.io/WebDevSimplified
⏱️ Timestamps:
00:00 - Introduction
00:25 - Dynamic Module Imports Explained
03:30 - Example 1: Code Splitting
05:40 - Example 2: Reduce Memory Usage
09:14 - Example 3: Increase Code Performance
#DynamicModules #WDS #ES6

Пікірлер: 285
@oussamakhalfi1751
@oussamakhalfi1751 2 жыл бұрын
this channel + fireship made my brain bigger
@mohammadsiddiq6056
@mohammadsiddiq6056 2 жыл бұрын
Agreeeeeeeed
@nishantaanjaneyjalan8583
@nishantaanjaneyjalan8583 2 жыл бұрын
So fucking trueeee
@divinsmathew
@divinsmathew 2 жыл бұрын
+ Kevin Powell as well!
@bonleofen
@bonleofen Жыл бұрын
What? Isn't fireship a troll channel?
@atreysinainadkarni5453
@atreysinainadkarni5453 Жыл бұрын
Hear hear.
@grmancool
@grmancool 2 жыл бұрын
The letter g: You want me *Kyle writing the word admin: I want you baby*
@nishantaanjaneyjalan8583
@nishantaanjaneyjalan8583 2 жыл бұрын
My sugar boo
@mtgamer101
@mtgamer101 2 жыл бұрын
Looked for this, was not disappointed.
@MomoCoder
@MomoCoder 2 жыл бұрын
Immediately started searching for this comment :D. I have same issues, esp. function gets really weard when I type c before n.
@nishantaanjaneyjalan8583
@nishantaanjaneyjalan8583 2 жыл бұрын
@@MomoCoder weird*
@MomoCoder
@MomoCoder 2 жыл бұрын
@@nishantaanjaneyjalan8583 thanks
@anticsBack
@anticsBack 2 жыл бұрын
Clear, simple and to the point as always. Thank you Kyle!
@legionsra
@legionsra 2 жыл бұрын
@Web Dev Simplified I would recommend you to extend for another video talking about the caveats or the things to bear in mind about imported modules. For instance, if they launch their own event listeners or any other side effect, when will they die, or how do we release the memory of those imported instances (not the imported file, but the instance), or even more complicated to understand, what would happen if moduleA imports moduleB, which imports moduleA, this definitely will be important for those who share a lot of utils dynamically imported.
@davzmore3623
@davzmore3623 2 жыл бұрын
Best js tips on KZbin, thank you for the effort to put out these videos.
@amittraspal
@amittraspal 2 жыл бұрын
The way kyle demonstrates the example...... that's what we call examples. Super useful, and relatable to actual scenarios.
@johnnydriesen7575
@johnnydriesen7575 2 жыл бұрын
Nice, clear and usefull examples. Thanks Kyle !
@BsiennKhan
@BsiennKhan Жыл бұрын
I love your style of explanation, clear, concise, simple with examples. Thank you
@Alessandro-nq3tm
@Alessandro-nq3tm 2 жыл бұрын
Dynamic import + async await = perfection :)
@achtube85
@achtube85 2 жыл бұрын
Awesome and clear explanations, as always! Gracias, Kyle!
@alfiartya23
@alfiartya23 7 ай бұрын
Your explanation for the translation example just blow my mind! Thank you so much Kyle, always delivering good explanation
@jimzhang32
@jimzhang32 2 жыл бұрын
My guy Kyle is always productive!
@ErickPereziChido
@ErickPereziChido 7 ай бұрын
Great tutorial! I immediately starting using dynamic module importing in my work project after watching this. Thank you!
@oluwaseunismaila8522
@oluwaseunismaila8522 2 жыл бұрын
Your tutorials are simply amazing. Confusing concepts clearly explained.
@helgaludwig793
@helgaludwig793 Жыл бұрын
Wow, thank you so much! this helped me so much cause all modules are switching to import
@dinesh08ification
@dinesh08ification 2 жыл бұрын
Wow, this actually helps a lot, learnt something new today
@heydaddy59
@heydaddy59 2 жыл бұрын
Elegant! Thanks Kyle for sharing this!
@erikuriegas97243
@erikuriegas97243 2 жыл бұрын
Thank you for what you do, you have truly helped me understand something than can be so complex
@MrQVeeBoo
@MrQVeeBoo Жыл бұрын
very clear explanation and easy to understand with sample. thx.
@habibishuta4896
@habibishuta4896 2 жыл бұрын
best Programming channel on youtube ♥️♥️♥️
@ShivamJha00
@ShivamJha00 2 жыл бұрын
Best web development channel*
@JackBrunsion
@JackBrunsion 2 жыл бұрын
Great explanation and demonstration!
@ThugLifeModafocah
@ThugLifeModafocah 2 жыл бұрын
Very good tips indeed. Thanks.
@ChrisAthanas
@ChrisAthanas 2 жыл бұрын
Always clear and no fluff Props
@techhype3453
@techhype3453 2 жыл бұрын
super teaching style great explanation
@sudarshanprajapati9742
@sudarshanprajapati9742 2 жыл бұрын
This video is really valuable for me. Thanks
@bhaveshverma8629
@bhaveshverma8629 2 жыл бұрын
Very Nice tutorials. The way use explain is amazing. I always saw your tutorial and get filled with knowledge. Thanks for putting out amazing content.
@HumbertoRincon
@HumbertoRincon 2 жыл бұрын
Useful use cases, thanks Kyle
@amithbhagat
@amithbhagat 2 жыл бұрын
Thank you Kyle, it is really helpful.
@ArKy326
@ArKy326 2 жыл бұрын
Always learning new with js tnx mr. Kyle!
@mrarsenal10vn
@mrarsenal10vn 2 жыл бұрын
Thanks, Kyle. Really useful
@Musikur
@Musikur 2 жыл бұрын
This is actually really cool, I did not know about this.
@raghunathvadlakonda810
@raghunathvadlakonda810 2 жыл бұрын
Really Really Worth it. @Kyle you are awesome.
@willyhorizont8672
@willyhorizont8672 2 жыл бұрын
thanks you're really helpful
@abhijiths148
@abhijiths148 2 жыл бұрын
Excellent topic... Thanks 👍
@infinitepurelive
@infinitepurelive 2 жыл бұрын
Awesome content as always
@avneet12284
@avneet12284 2 жыл бұрын
This was truly great
@sean9829
@sean9829 2 жыл бұрын
Wow. Didn’t know about this one. Thanks
@sreeragmmundayadan6057
@sreeragmmundayadan6057 2 жыл бұрын
Really helpful 👍
@agoodcode
@agoodcode 2 жыл бұрын
Great content as always 👍🏻👍🏻👍🏻
@haoranxu4465
@haoranxu4465 2 жыл бұрын
This is so useful☺️!
@Aaronmoreno
@Aaronmoreno 2 жыл бұрын
you're the best kyle!
@habibishuta4896
@habibishuta4896 2 жыл бұрын
love your content man
@LeoPlaw
@LeoPlaw 2 жыл бұрын
Awesome! I was looking for this solution months ago. Better late than never! Now I have some code to update. =)
@hiroyukinumaguchi1984
@hiroyukinumaguchi1984 2 жыл бұрын
Thank you!!
@khoaiviet7436
@khoaiviet7436 2 жыл бұрын
Thank you. This very helpful
@Lahiru_Udana
@Lahiru_Udana 2 жыл бұрын
awesome. thanks
@user-pn7hp3hc3q
@user-pn7hp3hc3q 5 ай бұрын
Good at explaining bro keep it up
@tanaseadrian8305
@tanaseadrian8305 Жыл бұрын
awesome tutorial
@jhandgreat7079
@jhandgreat7079 2 жыл бұрын
Thanks bro!
@PierreSoubourou
@PierreSoubourou 2 жыл бұрын
thanks for your videos text seems to be getting a little bigger, that's great
@stanislavmalyshev5209
@stanislavmalyshev5209 2 жыл бұрын
Good job!
@ManuelLopera
@ManuelLopera 2 жыл бұрын
This is very useful when using huge libs like pdf.js 👏👏👏
@nikolromick6134
@nikolromick6134 2 жыл бұрын
Would be great if you show your network loading while demonstrating code usage with example
@CottidaeSEA
@CottidaeSEA 2 жыл бұрын
Sort of but at the same time it wouldn't. The issue with these examples is that they are too small in scale. It would therefore not have a big enough impact on the network. This is similar to how you'd use async or defer to load scripts in a browser by the way.
@md.asifal-mahmud5952
@md.asifal-mahmud5952 Жыл бұрын
Thanks a lot
@RadiGamer
@RadiGamer Жыл бұрын
damn, that was useful! Thanks a lot man :D
@dimitridoroshko
@dimitridoroshko 2 жыл бұрын
"Hi" in Russian is "privét". Thanks for the video, it was helpful to many of those learning JavaScript and myself included :3
@definty
@definty 2 жыл бұрын
I thought that was pasiba
@SealedKiller
@SealedKiller 2 жыл бұрын
@@definty That would be thank you.
@thefreeze6023
@thefreeze6023 2 жыл бұрын
@@definty spasibo, pronounced spasiba means thanks you
2 жыл бұрын
zdarova
@nightcoder5k
@nightcoder5k 2 жыл бұрын
According to Google: “Hi” in Russian - Привет (privyet)
@mehinhuseynova1426
@mehinhuseynova1426 2 жыл бұрын
Thank you
@DuyTran-ss4lu
@DuyTran-ss4lu 2 жыл бұрын
Awesome!
@ozzyfromspace
@ozzyfromspace 2 жыл бұрын
Awesome video Kyle! Super informative. I do have one potential concern though. The way you wrote your code in the last example on conditional imports for your render function, you rerun the import function on every iteration of the shapes array. If your shapes array had 500 objects in it, you’d be running import many, many times! My recommendation here would be to memoize the imports. In particular, you can create an initially empty object, and on your first loop, add a key value pair of the shape and the render function that is returned from the import. Then on subsequent loops, check to see if a render object already exists, and if so, use it. Otherwise create another key value pair. This was a very useful video for me. I knew how to do this with the require syntax in node.js, but had no idea you could do this for module imports. I think I tried once, but it didn’t work cuz I treated it like a synchronous operation when in fact it returned a promise. Very cool stuff bro, keep it up! 🥳✨
@Vibestr
@Vibestr 2 жыл бұрын
would you mind writing out an example of this please?
@GNXClone
@GNXClone 2 жыл бұрын
The first time it's imported, it's in memory and stays resident. Subsequent imports of the same JS file are practically no-ops.
@jasurmusaev7234
@jasurmusaev7234 2 жыл бұрын
thank you
@lasithadulshan7357
@lasithadulshan7357 2 жыл бұрын
Shot & Sweet
@raye3007
@raye3007 Жыл бұрын
謝謝分享!!
@7heMech
@7heMech Күн бұрын
Thanks.
@abhilashmund
@abhilashmund 2 жыл бұрын
Wow that’s awesome
@m12652
@m12652 Жыл бұрын
Nice!
@vhawkins8289
@vhawkins8289 2 жыл бұрын
This is cool. 😎 Currently, are the files downloaded each time the code is run?
@imsarvesh_
@imsarvesh_ 2 жыл бұрын
Why this channel doesn’t have 1M subscribers?
@aziaev
@aziaev 2 жыл бұрын
nice and useful
@oldclient
@oldclient 2 жыл бұрын
Good stuff
@matheussoares1138
@matheussoares1138 Жыл бұрын
thanks
@shaikshavalisyed2012
@shaikshavalisyed2012 2 жыл бұрын
One of the best features of js.
@franciscod5987
@franciscod5987 2 жыл бұрын
Hi Kyle I had a question about the last example, so when you go through the forEach loop you run the ‘import’ function for every item in the array, does that mean you RE-import the files every time?
@me_manish_prajapati
@me_manish_prajapati 2 жыл бұрын
I think, once the file is downloaded it will use downloaded code only. So it'll check whether do we have that file or not. ( Same as React lazy loading works )
@kirayatail
@kirayatail 2 жыл бұрын
Hey, I learned something today. Have a like!
@Sagarclips
@Sagarclips Жыл бұрын
One drawback of dynamic import is that Tree shaking is not possible so if you are loading big module, bundler will load all exports from the module. But yes we can eliminate loading of unnecessary modules. That's a big benefit.
@shubhamlatiyan7972
@shubhamlatiyan7972 2 жыл бұрын
11:14, async await will not work in foreach loop
@techtonight882
@techtonight882 2 жыл бұрын
Two questions: 1. Wouldn't rectangle.js imported twice now? 2. Since we made forEach function async, and triangle.js is a significantly larger file from rectangle.js, then wouldnt it render rectangle and triangle out of order?
@GNXClone
@GNXClone 2 жыл бұрын
Wow! Nice! "This is going to save us time, memory and space" I'm curious to know what the difference is between memory and space. I've always considered memory === space.
@uahnbu
@uahnbu 2 жыл бұрын
Hey, your video really broaden your knowledge. Still, I've some wondering. What if I want to create a new instance of the imported Class, e.g. import { MyClass } from 'lib.js'; const obj = new MyClass(); and the constructor takes quite a little time. Is it beneficial to use dynamic import in this case, will some time to be spent to create the new obj every time the function is called?
@HELIOSsanta
@HELIOSsanta 6 ай бұрын
Hello my dear how You doing? Man You did a great job thanks so much your thought change Me a lot thanks so much.
@HaNaxHeart
@HaNaxHeart 2 жыл бұрын
amazing
@me_manish_prajapati
@me_manish_prajapati 2 жыл бұрын
Some questions: Should we use this in react-redux? For actions and dispatch It'll download the whole file and then by destructuring we will pick one method, so is there any method where we can download one method from .js file? Thanks, Kyle, You always know what we need to know about the Web.
@monireol
@monireol 2 жыл бұрын
Awesome
@franciscojunior3138
@franciscojunior3138 2 жыл бұрын
Nice.
@INAVACL
@INAVACL 2 жыл бұрын
AMAZING
@bryanenid1228
@bryanenid1228 2 жыл бұрын
What is the advantages of using this than using require() ? Just the async?
@annguyenhoangphu451
@annguyenhoangphu451 2 жыл бұрын
I have a question that when we use multiple time the dynamic import of the same is file, do the browser will download every single time or just one time and save in memory?
@fabaladibbasey7453
@fabaladibbasey7453 2 жыл бұрын
Nice one
@kalokal5812
@kalokal5812 2 жыл бұрын
I'm torn between feeling like this is amazing for performance and getting rid of 50 lines of imports at the top of all my files and it making the code itself less readable... Also how well does this work with automatically updating imports (e.g. in VSCode when you change file names)?
@Vipers992
@Vipers992 2 жыл бұрын
Honestly if I did these dynamic imports in any corporate codebase with 30+ engineers collaborating on it, people will really think i'm just being pretentious and not sticking with the format. All the files get bundled anyway.
@NgocNamNguyenHcm
@NgocNamNguyenHcm 2 жыл бұрын
10:33 in this last example, does this code load/import 3 times, in stead of 2 times according to the original code?
@duffscs
@duffscs 2 жыл бұрын
Probably not thanks to browser caching
@WebDevSimplified
@WebDevSimplified 2 жыл бұрын
It should only load twice. Since the second time it fetches the file it is already downloaded it will just use the downloaded version.
@NgocNamNguyenHcm
@NgocNamNguyenHcm 2 жыл бұрын
@@WebDevSimplified thank you 😊
@uahnbu
@uahnbu 2 жыл бұрын
If you include IIFE functions in the lib, such as console.log, varA++, etc, when you import it multiple times, these IIFE functions will only be called once, due to the behavior of caching.
@legionsra
@legionsra 2 жыл бұрын
@@WebDevSimplified I just checked this, and it is kept in memory, like when you add < script type="module" > to a page. There will be no more networks calls, not even for the cached version, if you refresh the page, then you will get the cached (or from service workers) if headers allows so, and then back to - only memory - usage.
@the_BetaDev
@the_BetaDev 2 жыл бұрын
In the last case, will it import every time the loop runs? like we run render rectangle twice so will it import that twice because it's in a loop?
@JayGanatra
@JayGanatra 2 жыл бұрын
Like, we can use this for datatables, to first load the page before loading the data?
@karolsyta1742
@karolsyta1742 2 жыл бұрын
Can I use async/await with default import name as in translations example? Where to put try .. catch then?
@hnccox
@hnccox 2 жыл бұрын
Me showing up to my boss: "I created a render engine for different shapes" The render engine:
@xAxtroz
@xAxtroz 2 жыл бұрын
Curious, are you using Promise.then((args) => { console.log(args) }) instead of Promise.then(console.dir) out of habit, to be explicit or for another reason? Mind sharing your thoughts? I'm talking in a scenario where you just want to dump something in the console.
@larsdaemon6104
@larsdaemon6104 2 жыл бұрын
awesome
@iamwilly8223
@iamwilly8223 2 жыл бұрын
Hi, sorry for my bad English, I'm Spanish. Does anyone know a book to learn Javascript using good practices? For Frontend and Backend, I really want to learn more about Vue Js and Node Js
@sky78710
@sky78710 Жыл бұрын
Can you explain that with using webpack jsnop bundles so that selection bundle dynamically. Please.
@trusterzero6399
@trusterzero6399 2 жыл бұрын
Does this automatically cache or do we need to take care of that manually?
@CodingEd
@CodingEd 2 жыл бұрын
Nice video, but here the question, is this method work with fw like vue?
@dave6012
@dave6012 2 жыл бұрын
Kyle this is such a cool idea! Is it possible to implement this with a react app aka something that is bundled with webpack? Sounds like maybe not since it has to compile everything anyway 🤔
@doc8527
@doc8527 2 жыл бұрын
it's ready existed for a while. As far as I know, Next.js has dynamic import that does advanced jobs like this, which is essentially from the idea of React.Lazy (reactjs.org/docs/code-splitting.html#reactlazy). As I skim through the comment section, it's unfortunate that a lot of Devs had no idea the library they are using daily especially React. Vue and Angular probably need to do some extra research to confirm this feature, but I pretty sure they existed here and there.
Learn CSS Scroll Snap In 6 Minutes
6:39
Web Dev Simplified
Рет қаралды 135 М.
Another 5 Must Know JavaScript Features That Almost Nobody Knows
22:42
Web Dev Simplified
Рет қаралды 212 М.
We Got Expelled From Scholl After This...
00:10
Jojo Sim
Рет қаралды 13 МЛН
DELETE TOXICITY = 5 LEGENDARY STARR DROPS!
02:20
Brawl Stars
Рет қаралды 13 МЛН
New Gadgets! Bycycle 4.0 🚲 #shorts
00:14
BongBee Family
Рет қаралды 16 МЛН
Speed Up Your React Apps With Code Splitting
16:50
Web Dev Simplified
Рет қаралды 367 М.
10 Tailwind Classes I Wish I Knew Earlier
13:31
Web Dev Simplified
Рет қаралды 161 М.
Learn JavaScript Event Listeners In 18 Minutes
18:03
Web Dev Simplified
Рет қаралды 566 М.
Require vs Import Javascript
22:39
Monsterlessons Academy
Рет қаралды 75 М.
Junior Vs Senior Code - How To Write Better Code
22:13
Web Dev Simplified
Рет қаралды 1,1 МЛН
Learn Debounce And Throttle In 16 Minutes
16:28
Web Dev Simplified
Рет қаралды 177 М.
5 MORE Must Know JavaScript Features That Almost Nobody Knows
18:05
Web Dev Simplified
Рет қаралды 179 М.
All useEffect Mistakes Every Junior React Developer Makes
22:23
Tips For Using Async/Await in JavaScript
16:26
James Q Quick
Рет қаралды 394 М.
5 JavaScript Concepts You HAVE TO KNOW
9:38
James Q Quick
Рет қаралды 1,4 МЛН
We Got Expelled From Scholl After This...
00:10
Jojo Sim
Рет қаралды 13 МЛН