🔧 ProgrammierungThe Cascade Runs Ahead of the Flip(16.09.2026 um 02:21 Uhr)
🔧 ProgrammierungWeekly Dev Log 2026-W19(16.09.2026 um 02:30 Uhr)
🔧 ProgrammierungI wanted to remember what changed after an AI coding session(16.09.2026 um 02:34 Uhr)
🔧 ProgrammierungYour change process governs code. This was not code.(16.09.2026 um 02:39 Uhr)
🔧 ProgrammierungThe Cascade Runs Ahead of the Flip(16.09.2026 um 02:21 Uhr)
🔧 ProgrammierungWeekly Dev Log 2026-W19(16.09.2026 um 02:30 Uhr)
🔧 ProgrammierungI wanted to remember what changed after an AI coding session(16.09.2026 um 02:34 Uhr)
🔧 ProgrammierungYour change process governs code. This was not code.(16.09.2026 um 02:39 Uhr)

🔧 Programmierung 🕛 vor 1 Monat 3 Min Lesezeit
0

Don't trust your SVG optimizer. Render-diff its output.

↗ Quelle (dev.to)
🗣️ Stimme:
📑 Inhaltsübersicht

SVG optimizers are wonderful right up to the day one quietly breaks an icon.



Run SVGO (or any optimizer) across a big icon set and you'll eventually hit it: a <g> gets collapsed, a path gets rewritten into a mathematically "equivalent" form, and in most renderers it looks identical, but in one specific renderer, or at one specific size, it's subtly wrong. A shape that was outlined is now filled. A stroke disappears. You don't notice until it's in production, because it didn't show up on the five icons you spot-checked.



Here's the uncomfortable part: most optimizers guarantee "smaller," not "renders the same." Those are different promises. An optimizer can shave bytes and, on an edge case, change what the file draws. The transforms are usually safe. "Usually" is the problem.






The fix isn't a better optimizer. It's verification.



Instead of trusting that a transform preserved rendering, check it. After optimizing, rasterize the original SVG and the optimized SVG, compare the two bitmaps, and if they diverge beyond a small tolerance, throw the optimized version away and fall back.



The guarantee flips from "these transforms are provably safe" (hard, and false in the edge cases) to "the pixels didn't change" (easy to check, and exactly what you care about).



A sketch of the idea:




CODE
opt := optimize(original)         // your SVG minifier of choice
a := rasterize(original, 512) // longest edge 512px is plenty
b := rasterize(opt, 512)
if sameSize(a, b) && diffFraction(a, b, tolerance) < 0.02 {
use(opt) // pixels match: trust it
} else {
use(fallback(original)) // diverged: don't ship it
}






A few things that matter in practice:





  • Flatten onto an opaque background before comparing. A shape that lost its fill and fell back to transparent should count as a difference, not get masked by alpha.


  • Allow a small per-channel tolerance (say 16/255). Anti-aliasing shifts sub-pixels when path data is rewritten; that's fine. A filled-vs-unfilled shape is not.


  • A small render is enough. You're catching gross divergence (a dropped stroke, a flipped fill), not fine detail, so a 512px raster keeps the check cheap.



You render twice, which isn't free, but for build-time optimization of an icon set you pay it once and never ship a broken icon.






The tools



The optimizer I use is silk, a pure-Go SVG optimizer in the spirit of SVGO (path data, structural passes). It ships as a single static binary, no Node toolchain, which is why it drops into a Go service or a minimal CI image where a JS toolchain would be a pain. Like most optimizers, it guarantees smaller, not identical, so the render-diff above is the layer I put around it: it lives in



There's a sibling for fonts, woffify: TTF/OTF/WOFF to WOFF2 plus glyph subsetting (via HarfBuzz), one binary. A raw TTF shipped instead of a subsetted WOFF2 is usually two-thirds-plus wasted bytes.




CODE
woffify -subset-text "$(cat page.txt)" < Inter.ttf > Inter.woff2








If you optimize SVGs at scale, steal the render-diff idea even if you never touch these tools. It's the cheapest insurance against the one broken icon you won't catch by eye.

Vollständiger Original-Artikel
Den kompletten Beitrag mit allen Details direkt auf dev.to lesen.
↗ Original-Artikel auf dev.to lesen
Wie bewertest du diesen Beitrag?
1 Klick Feedback
Teilen mit Netzwerk & Team:

Community-Analysen & Experten-Meinungen 0

Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
Community Pulse: Relevanz-Einschätzung
1 Klick Experten-Votum
🔴 Akute Relevanz 0%
🟡 In Evaluierung 0%
🟢 Keine Auswirkung 0%
Spannende Innovation 0%
Verwandte Story-Cluster & Quellen (Vektor-KI)
Port 8095 Engine
1 Quelle
Building a SOC 2 Evidence Collector: A Small-Team Alternative to Manual Audit Prep
1 Quelle
From Ring to Repo: Predicting Developer Fatigue Using Oura Data and Random Forest
1 Quelle
The Cascade Runs Ahead of the Flip
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Don't trust your SVG optimizer. Render-diff its output.

Thematisch verwandte Begriffe: Dont, trust, your, optimizer · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...