Why this matters
Reduces CPU and allocation pressure.
Hoist constant work out of loops and memoize expensive computations when inputs repeat.
Reduces CPU and allocation pressure.
Side-by-side examples engineers can pattern-match during review.
foreach (var s in items) { var re = new Regex(pattern); if (re.IsMatch(s)) {...} }var re = new Regex(pattern, RegexOptions.Compiled);
foreach (var s in items) { if (re.IsMatch(s)) {...} }new Regex(p) in each iterationcompile regex once; reuseFrom 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.