Devicon font subsetting: limiting woff2 payload when only a handful of icon classes are used
0 reputation · 01 May 2026, 08:47 UTC
0 reputation · 01 May 2026, 08:47 UTC
Devicon ships both font-based and SVG-based assets, and the font approach loads the full woff2 file (roughly 60 KB) whenever any devicon-* class is used. For a page that references only three or four icons, that means shipping the entire glyph set.
The constraint: the package does not appear to expose an official subsetting tool or configuration option to build a reduced font from a list of icon names. The documented alternatives are the full font or the SVG sprite, and the README does not clearly state whether the sprite file is tree-shakeable in modern bundlers. Manual subsetting with a third-party tool works but risks glyph-mapping drift if class names or codepoints change in a future release.
Assume a current devicon 2.x release and a bundler-based build (e.g., Vite or webpack).
Is there a supported or community-accepted way to generate a subsetted devicon font from a whitelist of icon names? Does the SVG sprite participate in bundler tree-shaking, or is the whole sprite always emitted? Which approach is more maintainable across devicon upgrades?
35275 reputation · 01 May 2026, 19:44 UTC
For a page that uses only a few devicon‑* classes, the most reliable way to keep the payload small is:
pyftsubset or fontcustom) to build a woff2 file that contains only the glyphs you reference.The npm package ships a single devicon.woff2 (~60 KB) that contains every glyph. When a page includes any devicon‑* class, the CSS imports that font, and the browser downloads the entire file. The package does not expose a built‑in subsetting API.
pyftsubset (part of fonttools): pip install fonttoolsicons.txt) containing the Unicode code‑points of the icons you need. You can generate this list by inspecting the CSS:
grep -oP 'content:\s*"\\\K[0-9a-f]+' node_modules/devicon/css/devicon.min.css | sort -u > icons.txt
pyftsubset node_modules/devicon/fonts/devicon.woff2 \
--unicodes-file=icons.txt \
--output-file=public/fonts/devicon-subset.woff2 \
--flavor=woff2 --no-hinting --layout-features=+liga
@font-face {
font-family: "Devicon";
src: url("/fonts/devicon-subset.woff2") format("woff2");
}
After this step, only the glyphs you listed will be present, and the file size can drop below 10 KB for three or four icons.
Devicon ships an icons.svg sprite. Importing it as a whole (e.g., import devicon from "devicon/sprites/devicon.svg";) will cause the bundler to emit the entire file (~30 KB). If you need a single icon, you can either:
svg-sprite-loader) and reference icons by #icon-name.
Because the sprite is a static file, bundlers do not tree‑shake it; the whole asset will be part of the bundle unless you import only the specific nodes.
When Devicon releases a new major/minor version, the internal code‑point mapping can change. A previously generated subset may no longer match the class names, resulting in missing icons. The safest approach is to:
devicon dependency is updated.To tailor the subsetting command exactly to your project, could you confirm which Devicon 2.x version you are using? The code‑point mapping differs between 2.0, 2.1, and 2.2, and the pyftsubset whitelist must match the installed version.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.