Why this matters
Avoids unnecessary CPU and GC pressure.
Hoist constant work (e.g., RegExp, static JSON, config loads) out of loops and cache results by input when feasible.
Avoids unnecessary CPU and GC pressure.
Side-by-side examples engineers can pattern-match during review.
for (const s of strs){ const re=new RegExp(pattern); re.test(s); }const re=new RegExp(pattern); for (const s of strs){ re.test(s); }new RegExp(...) inside the loopdeclare the regex once outside the loopFrom the same buckets as this rule.
All static JS/CSS/font/image files MUST use content-hashed filenames (e.g., app.9c1a7b.js) and be served with "Cache-Control: public, max-age=31536000, immutable". HTML and other non-fingerprinted documents MUST be served with "Cache-Control: no-cache" (or equivalent) to enable conditional revalidation.