From the course: Developing for Web Performance

Unlock this course with a free trial

Join today to access over 22,600 courses taught by industry experts.

Lazy-loading JavaScript modules with import()

Lazy-loading JavaScript modules with import()

From the course: Developing for Web Performance

Lazy-loading JavaScript modules with import()

- [Instructor] Earlier in the course, I talked about lazy loading images and other media assets to improve performance by only loading them into the browser if the user got to them well, we can sort of use that same idea to lazy load JavaScript modules and their associated assets only when they're interacted with and needed. This is achieved using the import statements in JavaScript and it's best explained through a practical example. So I built a very, very basic example. Let's say I have an app and the app has a button. When I click on that button a gallery pops up showing some images, I guess that this is a very basic example. Now, imagine this button here is something far more complex some advanced JavaScript feature like a dynamic gallery or a shopping cart or an advanced form or something that could require a lot of JavaScript or maybe even a lot of data like an image or a video or something like that. The…

Contents