SVG framework optimizations
This tutorial is part of Iconify SVG Framework tutorial.
This tutorial has several parts:
Most site optimization tutorials tell you that you should put scripts in footer before. What about Iconify? You can put Iconify script in head section (between and ) or in footer before .
So what's the difference?
If you put link to Iconify in footer before, it will load after entire page has been loaded, not blocking rendering. That's good for page loading speed.
However, it also means icon placeholders won't be replaced until entire page has been loaded. Iconify cannot start doing its thing until it has loaded.
If you put link to Iconify in head section (betweenand ), it will load immediately. Downside is, any script tag placed in head section blocks page rendering until script has loaded.
Iconify SVG framework is rather small (about 32kb uncompressed), delivered from fast CloudFlare CDN. It takes fraction of second to load.
Benefit of placing Iconify script in head section is, it can start replacing icons right away. That means, if you have a large page, icons will be replaced as soon as part of document loads instead of waiting for an entire document to load.
There are pros and cons for each method. You should decide for yourself instead of blindly relying on recommendations from online website checkers. Online website checkers don't know what script does and how it works, so they always recommend putting all scripts in footer.
If your pages are small, probably better to put script in footer before. For example, this website has it in footer.
If your pages are large, dynamically generated, such as forum pages, it might be better to put script in head section. Forum pages might take several seconds to load, by placing script in head section, you make sure visitors see icons as soon as possible.
If you are experiencing flickering during load (page loads, then renders, then icons are replaced), you probably should move Iconify SVG framework script to head section.
Iconify SVG framework is fast, but you can make it even faster by helping Iconify figure out what icons to load.
There are several ways to improve icon loading:
If your page is likely to display additional icons after initial page load, such as AJAX forms or React/Angular application, you can tell Iconify SVG framework to pre-load those icons. Then, when your script will display those icons, Iconify would already have data for those icons retrieved from API.
This also helps to reduce number of API queries. Loading icons in bulk is faster than loading them one by one.
To pre-load icons add this code anywhere after including Iconify script:
Argument to loadIcons (or preloadImages for version 1.0) is an array of icons you want to load.
To use this function, make sure either Iconify is placed in footer beforeor put it in bundle with SVG framework. Otherwise, SVG framework might be loaded faster than your script, scan DOM and get shorter list of icons to retrieve, splitting it into multiple API queries.
If in your development process you are creating script bundles, where you put everything you need, including Iconify SVG framework, you should consider adding icon data to your bundle.
This will reduce number of HTTP queries and it will make sure icon data is available instantly.
See bundled icons page for details.