My requirements:
- Icons will be used "above the fold", including the site-wide navigation header/menu
- Page should initially render without waiting for icons to load (i.e. icons are not added to the HTML nor are they part of critical CSS). In other words icons are considered as progressive enhancement, not core functionality.
- Icons should be able to be cached, as many will be used on every page
- Do not cause too many extra HTTP requests
Possible solutions (and why they may not work):
Webfont
As it's applied using CSS, it will become part of the critical CSS and cause extra roundtrips before the page can render = violation of requirement 2
One SVG file per icon
Causes one HTTP request per icon = violation of requirement 4
Embed SVG sprite and <use>
it
Will be embedded on every single page and hence non-cacheable = violation of requirement 3
External SVG sprite
This is the only solution I can think of that provides efficient HTTP requests (only one!), will support caching, and won't be required before the initial content can be painted by the browser. The sprite could be generated easily using something grunt-svgstore but I'm not sure exactly how the rest would work, particularly CSS. Using <object>
with an external link sounds plausible for the HTML (assuming a polyfill for IE is used) but then what about icon backgrounds for CSS - reference them by URL?