- Separating your app into modules: Building your app with modules makes it more efficient and increases the performance of your code. By using these modules, you can lazy load your code and you can use only the code that you need and avoid unused code.
- The defer method is used by default
- It imports your modules dynamically
How to use modules
And inside your
main.js you can import and export your modules:
Using the export method in
As shown in the above example, it’s easy to use ECMAScript modules — there is no complex code in this case.
In another way, you can set the
.mjs extension to the file so the browser can identify the module. But this doesn’t make big changes if you set the type attribute as a module to the script tag.
I don’t need to use bundlers anymore?
Addy Osmani and Mathias Bynens explain in this article that you probably don’t need a web bundler such as webpack if you develop a web app with less than 100 modules. You can check out the article where they have exposed the best practices and good usage of ECMAScript modules here.
Find the code in the GitHub repository here.
Originally published on Zeolearn
Join My Class to learn Bootstrap on Skill Share
- Learn Bootstrap 4 in 30 min by building a Landing a Website
- Angular 6 and it’s new features, all explained in three minutes
- How to use routing in Vue.js to create a better user experience
- Learn how to create your first Angular app in 20 minutes