Use SVG Sprites for performance
mainFor improved performance, use sprite_icon instead of icon. This method references shared <symbol> definitions via <use href="..."> rather than inlining the full SVG code.
External Sprite (Default)
By default, Rails Icons serves a sprite at /rails_icons/sprite.svg. This is reachable even if the preview engine is behind authentication.
<%= sprite_icon "check" %>
# Renders: <svg><use href="/rails_icons/sprite.svg#heroicons_outline_check"></use></svg>You can override the location per icon:
<%= sprite_icon "check", sprite_location: "/assets/sprites.svg" %>Inline Sprite
To embed the sprite directly in your layout (reducing HTTP requests but increasing HTML size), set config.default_sprite_location = nil in your initializer and use the icons_sprite helper in your layout.
<body>
<%= icons_sprite %>
<%= sprite_icon "check" %>
</body>You can also generate a sprite for a specific subset of icons:
<%= icons_sprite ["check", "search"], library: "heroicons", variant: "outline" %># External sprite usage
<%= sprite_icon "check" %>
# Inline sprite usage
<%= icons_sprite %>
<%= sprite_icon "check" %>