Performance: Why modules are needed
MEDIUM IMPACT
This concept affects the initial load time and runtime efficiency by organizing code into reusable, isolated pieces.
// file readModule.js
export function readFile() { /* code */ }
// file writeModule.js
export function writeFile() { /* code */ }
// main.js
import { readFile } from './readModule.js';
// Only needed modules loadconst fs = require('fs'); const path = require('path'); // All code in one big file without separation function readFile() { /* big code block */ } function writeFile() { /* big code block */ } // Many unrelated functions mixed together
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Monolithic script file | N/A | N/A | Blocks rendering until fully loaded | [X] Bad |
| Modular code with imports | N/A | N/A | Loads smaller chunks, faster initial paint | [OK] Good |