Developer finds CMS images missed by build audit, cuts page weight 56x with CDN fixes
A developer auditing their portfolio site used build-output analysis to catch oversized bundled assets, but later discovered the method had a blind spot: images served dynamically from Sanity's CMS were never part of the build and went undetected. When the developer opened the blog index in a browser and measured actual network traffic, they found the page serving 16 post covers weighed 9.88 MB, with one image alone reaching 3.13 MB despite rendering at roughly 250 pixels wide. The root cause was that the image URL builder utility, urlFor, was only used in one component and was absent from the pages displaying post cover grids, meaning raw, untransformed CDN URLs were being served instead. The fix involved writing a lightweight helper function that appends Sanity CDN parameters — including width caps, fit constraints, format negotiation, and quality settings — to image URLs at render time. After the change, the same sixteen cover images measured just 182 KB in total, a 56-fold reduction, highlighting how static build audits cannot account for assets fetched dynamically at runtime.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)
Log in to join the discussion and vote.
Log in