DEV Community

Cover image for Make your Angular App faster using Dynamic import
mridul037
mridul037

Posted on

Make your Angular App faster using Dynamic import

Tips to make your angular app faster:

while importing your module using lazy loading helps

{ 𝑝𝑎𝑡ℎ: 'ℎ𝑜𝑚𝑒', 𝑐𝑜𝑚𝑝𝑜𝑛𝑒𝑛𝑡: 𝐻𝑜𝑚𝑒𝐶𝑜𝑚𝑝𝑜𝑛𝑒𝑛𝑡;}

To using loadChildren:

{𝑝𝑎𝑡ℎ: 'ℎ𝑜𝑚𝑒', 𝑙𝑜𝑎𝑑𝐶ℎ𝑖𝑙𝑑𝑟𝑒𝑛: './ℎ𝑜𝑚𝑒/ℎ𝑜𝑚𝑒.𝑚𝑜𝑑𝑢𝑙𝑒#𝐻𝑜𝑚𝑒𝑀𝑜𝑑𝑢𝑙𝑒'}

to make even better use dynamic import() function in Javascript.

{
𝑝𝑎𝑡ℎ: 'ℎ𝑜𝑚𝑒',
𝑙𝑜𝑎𝑑𝐶ℎ𝑖𝑙𝑑𝑟𝑒𝑛: () => 𝑖𝑚𝑝𝑜𝑟𝑡('./ℎ𝑜𝑚𝑒/ℎ𝑜𝑚𝑒.𝑚𝑜𝑑𝑢𝑙𝑒').𝑡ℎ𝑒𝑛(𝑚 =>
𝑚.𝐻𝑜𝑚𝑒𝑀𝑜𝑑𝑢𝑙𝑒)
},

import statement return a promise. you read more about in given link.

link:: https://javascript.info/modules-dynamic-imports

Top comments (0)