Rules Hub
Coding Rules Library
Rule priority, scope & exceptions
Use this to align rules with the senior-level structure (P0/P1/P2, scope, exceptions/tradeoffs).
Preload a bundle entry's transitive imports too, not just the entry chunk itself
When emitting a `<link rel="modulepreload">` (or similar preload hint) for a build manifest entry, also preload the chunks listed in that entry's own `imports` in the manifest — don't assume the entry is a self-contained leaf chunk.
Bad example
| 1 | const preloadUrl = `${origin}/static/${manifest['chart-lib'].file}`; |
| 2 | // only the entry chunk is preloaded |
Explanation (EN)
If the bundler ever splits the entry's dependencies into their own chunks, those chunks are only discovered after the entry itself loads and starts importing them — reintroducing the waterfall the preload was meant to remove.
Objašnjenje (HR)
Ako bundler ikad razdvoji ovisnosti entry chunka u zasebne chunkove, ti se chunkovi otkrivaju tek nakon što se sam entry učita i počne ih uvoziti — čime se ponovno uvodi kaskadno kašnjenje koje je preload trebao ukloniti.
Good example
| 1 | const preloadUrls = [ |
| 2 | `${origin}/static/${manifest['chart-lib'].file}`, |
| 3 | ...manifest['chart-lib'].imports.map((p) => `${origin}/static/${p}`), |
| 4 | ]; |
Explanation (EN)
Preloading the entry plus everything it transitively imports keeps the preload correct even if the bundler's chunking strategy changes later — it costs nothing today if the entry happens to be a leaf.
Objašnjenje (HR)
Preload entryja plus svega što on tranzitivno uvozi ostaje ispravan i ako se kasnije promijeni strategija chunkiranja bundlera — ne košta ništa danas ako je entry trenutno samostalan chunk.