Recoloring External SVGs in Mini-Programs with a Drop-Shadow Silhouette
Mini-program teams chasing every kilobyte of main-package budget can replace heavy iconfonts with lightweight external SVGs without losing the ability to theme icons via CSS. The approach is a pure CSS workaround that avoids generating multiple color variants of the same SVG asset.
Mini-program iconfont bundles waste package space because the entire glyph set is packed, base64 inlining inflates size by roughly 33%, and tree-shaking cannot prune unused glyphs. Swapping to on-demand external SVGs solves the size problem but breaks CSS recoloring: `<image>` is a native replaced element, so `color` never reaches the SVG interior. The workaround hides the real image above a clipped container and uses `filter: drop-shadow(0 H 0 currentColor)` to project a solid silhouette back into the visible area. The silhouette inherits `currentColor`, restoring full CSS color control. The technique works for single-color icons, requires matching translate and shadow offsets, and demands real-device testing for filter support. Click targets must live on the outer container because the visible icon is a rendering effect, not a DOM node.
The technique decouples shape from color by treating the SVG purely as an alpha mask and letting CSS paint the visible result—a pattern that echoes shader-based rendering in a CSS property.
Mini-program architecture forces a workaround that would be unnecessary in a browser with inline SVG support, highlighting how platform constraints can resurrect clever CSS hacks that the web community largely retired.
The base64 size penalty (33% larger than raw binary) is often overlooked in iconfont discussions, yet it compounds when the same CSS is duplicated across sub-packages.