Dynamic Loading, Lazy Loading, and Dynamic Imports * Mariya Baig

Mariya Baig
2 min readSep 25, 2023

--

In the world of web development, making websites load faster and use fewer resources is a big deal. Three cool tricks for achieving this are dynamic loading, lazy loading, and dynamic imports. Let’s break them down and see how they’re similar and different, all in simple terms.

Dynamic Loading — Load Stuff When You Need It

Dynamic loading is like getting stuff from a closet. Imagine you have a big closet with lots of things inside, but you don’t need everything all at once. Dynamic loading is when you only take out what you need when you need it.

Lazy Loading — Don’t Load What You Don’t See

Lazy loading is a cousin of dynamic loading. It’s all about not doing any work until you really have to. Think of it as only turning on the lights in a room when you walk into it and turning them off when you leave.

Dynamic Imports — Get Code on Demand

Dynamic imports are like ordering pizza. Imagine you’re building a big pizza, but you don’t want to put all the toppings at once; you want to add them one by one when you’re ready to eat. Dynamic imports let you do just that with your code.

Comparison between Dynamic Loading, Lazy Loading, and Dynamic Imports

How it works

Uses different tricks depending on what it’s loading, like using the Intersection Observer for pictures.

Waits to load things until they’re visible or required, often using the Intersection Observer for images.

Relies on the dynamic import() function to bring in code modules as you go.

Conclusion

Each tool has its own job, but they all work together to make the web a better place.

Originally published at https://mariyabaig.com on September 25, 2023.

--

--

No responses yet