taurus-media / module-hyva-svg-sprite
Optimize SVG rendering in Hyva themes by using SVG sprites.
Package info
github.com/taurus-media/module-hyva-svg-sprite
Type:magento2-module
pkg:composer/taurus-media/module-hyva-svg-sprite
Requires
- php: >=8.1
- hyva-themes/magento2-theme-module: *
- magento/framework: *
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-10-09 11:14:23 UTC
README
The Taurus_HyvaSvgSprite module optimizes SVG rendering in Hyva themes by automatically converting individual SVG icons into a single SVG sprite.
Overview
In standard Hyva themes, icons are rendered as individual <svg> elements directly in the HTML. While efficient, this can lead to a larger DOM size if many icons are used or if the same icon is repeated multiple times.
This module intercepts the Hyva\Theme\ViewModel\SvgIcons::renderHtml method. Instead of returning the full SVG content, it:
- Adds the icon to a centralized
SvgSpriteViewModel. - Returns a light
<svg><use href="#icon-id" /></svg>tag. - Renders all collected icons as
<symbol>elements within a hidden<svg>sprite at the bottom of the page (before the</body>tag).
Cached blocks
Blocks loaded from the block_html cache (e.g. Hyva product list items, catalog product widgets) never call
renderHtml, so their icons can't register themselves in the sprite. To cover this:
- every symbol added to the sprite is also stored in a persistent registry (
HYVA_SVG_SPRITE_REGISTRY, kept in theblock_htmlcache type, so it is flushed together with the cached blocks); - the
view_block_abstract_to_html_afterobserver (Observer\CollectCachedIcons) scans each block's output (cache hits included) for<use href="#icon-...">and adds the missing symbols from the registry.
Only blocks rendered before the sprite block (before.body.end) are covered.
Features
- Performance Optimization: Reduces the overall size of the HTML document by reusing SVG definitions.
- Automatic Integration: No changes needed to existing templates. It automatically plugins into Hyva's standard icon rendering logic.
- Zero Configuration: Works out of the box once enabled.
Installation
Via Composer
-
Install the module:
composer require taurus-media/module-hyva-svg-sprite
-
Run the following Magento commands:
bin/magento module:enable Taurus_HyvaSvgSprite bin/magento setup:upgrade bin/magento cache:flush
Manual Installation
- Copy the module files to
app/code/Taurus/HyvaSvgSprite. - Run the following Magento commands:
bin/magento module:enable Taurus_HyvaSvgSprite bin/magento setup:upgrade bin/magento cache:flush