Skip to content
Technical

SVG-Sprite-Systemen: Efficiënt Iconenbeheer

Maak efficiënte SVG-sprite-systemen voor grootschalige applicaties. Leer sprite-generatie, gebruikspatronen en prestatie-optimalisatietechnieken.

Robin Monteiro27 januari 202610 oktober 20266 min
Use this article with an AI assistant:
.md
SVG-Sprite-Systemen: Efficiënt Iconenbeheer
R
Robin Monteiro

Founder of VectoSolve

Self-taught developer, founder and sole developer of VectoSolve since 2024. He builds the conversion engine and the cutting, embroidery and 3D printing exports.

How this article was made: drafted with AI assistance, then edited and fact-checked before publication. About the author

Image vectorizationCutting machine filesEmbroidery filesSVG
Free previewNo signupFull-quality output

Key Takeaways

  • SVG-sprites combineren tientallen iconen in een enkele HTTP-aanvraag, waardoor de netwerkoverhead drastisch wordt verminderd
  • Het <symbol> + <use>-patroon laat je iconen eenmalig definiëren en overal op de pagina refereren
  • Externe sprites zijn het beste voor grote apps (cacheerbaar), terwijl inline sprites geschikt zijn voor kleinere sites (nul latentie)
  • Style sprites met CSS custom properties voor consistente afmetingen, kleurthema's en hover-states
  • Voeg altijd aria-hidden="true" toe aan decoratieve iconen en role="img" met <title> aan betekenisvolle iconen

Waarom SVG-Sprites?

Individuele SVG-bestanden betekenen aparte HTTP-aanvragen. Sprite-systemen combineren iconen in enkele bestanden, verbeteren de prestaties en vereenvoudigen het beheer.

SVG-sprite-sheets en icoon-systeemarchitectuur
SVG-sprites: één bestand, tientallen iconen, één HTTP-aanvraag

Voordelen van het Sprite-Systeem

Prestaties

Individuele Iconen:
50 iconen x 1 aanvraag = 50 aanvragen

SVG-Sprite:
50 iconen = 1 aanvraag

Beheer

Voordelen:

  • Enkele bron van waarheid
  • Eenvoudige updates
  • Consistente styling
  • Versiebeheer-vriendelijk

Sprite-Types

Externe Sprite

Apart gerefereerd bestand:

html
<!-- sprites.svg -->
<svg xmlns="http://www.w3.org/2000/svg">
  <symbol id="icon-home" viewBox="0 0 24 24">
    <path d="M10 20v-6h4v6h5v-8h3L12 3 2 12h3v8z"/>
  </symbol>
  <symbol id="icon-search" viewBox="0 0 24 24">
    <path d="M15.5 14h-.79l-.28-.27..."/>
  </symbol>
</svg>

<!-- Gebruik -->
<svg class="icon"><use href="/sprites.svg#icon-home"/></svg>

Inline Sprite

Ingebed in HTML:

html
<body>
  <!-- Verborgen sprite-container -->
  <svg style="display: none;">
    <symbol id="icon-home" viewBox="0 0 24 24"><path d="..."/></symbol>
  </svg>
  <!-- Gebruik overal op de pagina -->
  <svg class="icon"><use href="#icon-home"/></svg>
</body>

CSS-Achtergrond Sprite

Data URI-benadering:

css
.icon-home { background-image: url("data:image/svg+xml,..."); }

Pro Tip: Geef de voorkeur aan inline sprites voor above-the-fold iconen die direct moeten renderen, en externe sprites voor grote iconensets die profiteren van browsercaching tussen paginanavigaties.


A Full Year of Conversions for $49

Starter Annual: 25 conversions every month, $49 for the whole year. That is about $4.08 a month · Cancel anytime

Get the Annual Deal

Sprites Maken

Handmatige Creatie

xml
<svg xmlns="http://www.w3.org/2000/svg">
  <defs><style>.icon-stroke { stroke-width: 2; fill: none; }</style></defs>
  <symbol id="icon-1" viewBox="0 0 24 24"></symbol>
  <symbol id="icon-2" viewBox="0 0 24 24"></symbol>
</svg>

Geautomatiseerde Generatie

Met svg-sprite:

javascript
const svgSprite = require('gulp-svg-sprite');
gulp.task('sprite', () => {
  return gulp.src('icons/*.svg')
    .pipe(svgSprite({ mode: { symbol: { dest: '.', sprite: 'sprites.svg' } } }))
    .pipe(gulp.dest('dist'));
});

Webpack-Integratie

javascript
const SpriteLoaderPlugin = require('svg-sprite-loader/plugin');
module.exports = {
  module: { rules: [{ test: /\.svg$/, use: [{ loader: 'svg-sprite-loader', options: { extract: true } }] }] },
  plugins: [new SpriteLoaderPlugin()]
};

Gebruikspatronen

Basisgebruik

html
<svg class="icon icon-home" aria-hidden="true"><use href="#icon-home"/></svg>

React Component

jsx
function Icon({ name, size = 24, className }) {
  return (
    <svg className={`icon ${className}`} width={size} height={size} aria-hidden="true">
      <use href={`#icon-${name}`}/>
    </svg>
  );
}
<Icon name="home" size={20} className="nav-icon"/>

Vue Component

vue
<template>
  <svg :class="['icon', className]" :width="size" :height="size"><use :href="`#icon-${name}`"/></svg>
</template>
<script>
export default { props: { name: String, size: { type: Number, default: 24 }, className: String } }
</script>
"

Een goed gebouwd SVG-sprite-systeem is de ruggengraat van elk schaalbaar designsysteem. Het is het enige asset dat elke pagina en elk component raakt.

— Sarah Drasner, Engineering Director & SVG-Specialist

Sprites Stylen

css
.icon { width: 24px; height: 24px; fill: currentColor; }
.icon-primary { fill: var(--color-primary); }
.icon-lg { width: 32px; height: 32px; }

CSS Custom Properties

css
:root { --icon-size: 24px; --icon-color: currentColor; }
.icon { width: var(--icon-size); height: var(--icon-size); fill: var(--icon-color); }

Stroke Iconen

css
.icon-stroke { fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
SVG-iconen geoptimaliseerd voor web-apps en designsystemen
SVG-sprites stylen met CSS custom properties voor consistente design tokens

Free SVG Tools for Crafters

Design Checker · Color Separator · Mat Preview · Offset Generator · Text to SVG

Check Your SVG Free

Toegankelijkheid

Decoratieve Iconen

html
<button><svg class="icon" aria-hidden="true"><use href="#icon-settings"/></svg> Instellingen</button>

Betekenisvolle Iconen

html
<a href="/home"><svg class="icon" role="img" aria-label="Home"><title>Home</title><use href="#icon-home"/></svg></a>

Prestatie-Optimalisatie

Cachingstrategie

html
<link rel="preload" href="/sprites.svg" as="image" type="image/svg+xml">

Code-Splitting

javascript
async function loadSprite() {
  const response = await fetch('/sprites.svg');
  const svg = await response.text();
  document.body.insertAdjacentHTML('afterbegin', svg);
}

Sprite-Subsets

Maak kleinere sprites per sectie:

/sprites
  /navigation-icons.svg
  /social-icons.svg
  /editor-icons.svg

Voor applicaties met 100+ iconen, splits sprites per paginasectie of functiegebied. Dit voorkomt het laden van editor-iconen op pagina's die alleen navigatie-iconen nodig hebben.


Grote Iconensets Beheren

/icons
  /navigation
    home.svg
    menu.svg
  /actions
    edit.svg
    delete.svg
  /social
    twitter.svg
    facebook.svg

A Full Year of Conversions for $49

Starter Annual: 25 conversions every month, $49 for the whole year. That is about $4.08 a month · Cancel anytime

Get the Annual Deal

VectoSolve voor Iconensets

Gebruik VectoSolve om iconen te maken:

  1. Bronafbeeldingen converteren
  2. Opschonen en optimaliseren
  3. Combineren in sprite
  4. Deployen

VectoSolve biedt: schone paden, consistente viewBox, geoptimaliseerde output, klaar voor sprites.


Conclusie

SVG-sprite-systemen verbeteren iconenbeheer en prestaties drastisch. Kies de juiste aanpak — inline voor kleinere sets, extern voor grotere applicaties. Gebruik VectoSolve om schone, consistente iconen te maken die klaar zijn voor sprite-integratie.

Maak Je Iconenset

Tags:
svg sprites
iconen
prestaties
webontwikkeling
componenten
Share:

Try VectoSolve Now

Convert your images to high-quality SVG vectors with AI

AI-Powered Vectorization

Ready to vectorize your images?

Convert your PNG, JPG, and other images to high-quality, scalable SVG vectors in seconds.