Discussion Frontend Others React.js

Webpack – Lazyload component

Lazy, or “on demand”, loading is a great way to optimize your site or application. This practice essentially involves splitting your code at logical breakpoints, and then loading it once the user has done something that requires, or will require, a new block of code. This speeds up the initial load of the application and lightens its overall weight as some blocks may never even be loaded.

Webpack pack provides functionality to implement lazy load of modules.
One critical problem of SPA apps is that the bundle size is too large because at compilation time, webpack bundles all modules into one file.
But there is a webpack functionality to lazy load modules, so that they are not included in the bundle at compilation time, but dynamically included at runtime.
Traditional import syntax is

import ModuleName from 'module path';

can be

() => import(‘module path)


We can execute this function at anytime we want to load the module.

Stan

Stan is an experienced full-stack developer and software engineer who is focused on web and game development. He is enthusiastic about new technologies. Stan is highly skilled in many programming languages and frameworks, and he always tries to deliver the best approach.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *