Comments (3)
After reading that reply, I think I've overcomplicated it and didn't really answer question. So simple version:
- Script. Yes, you add script and that's it.
2 Files are hosted on API, not locally.
So why are icons not hosted locally? Because it is rather complex system. And now I'll write long answer...
For comparison, fonts are very simple - all icons are in one file. However this has downside - you can store only limited number of icons in file because with each icon it becomes bigger and every visitor must load entire collection.
Storing icons one by one is also a bad idea. Each icon requires separate HTTP request.
Iconify loads icons in bulk. For example, lets say you have these 3 icons on your page:
<span class="iconify" data-icon="ic-baseline-face"></span>
<span class="iconify" data-icon="ic-baseline-arrow-drop-down"></span>
<span class="iconify" data-icon="ic-round-sync-disabled"></span>
Iconify script scans page for those elements, retrieves list of icons: ic-baseline-face, ic-baseline-arrow-drop-down, ic-round-sync-disabled.
Then it sends API request: https://api.iconify.design/ic.json?icons=baseline-face,baseline-arrow-drop-down,round-sync-disabled&pretty=1 (I've added "pretty" parameter so you could see API response in readable format)
That response contains SVG for 3 icons. Then Iconify replaces SPAN elements with SVG using that data.
So why can't it be hosted locally? Because API request are complex. Responses are generated dynamically for each request. Each page might contain different icons, so they'll have different API requests.
In previous reply I've posted my solutions to this complex hosting issue.
It is not as simple as hosting font files, however tradeoff is ability to host unlimited number of icons. On API there are currently 42477 icons. That includes Google's Material Design Icons (both version 3 that you see in google's repository and newer version that you can see on material.io), Templarian's Material Design Icons (another over 3000 icons that perfect for websites that use material design), Font Awesome, Unicons, Jam Icons and many many more.
So for example you want to use on your website 3 material design icons mentioned above, but you also want to use "home" icon from Font Awesome 5 and cat emoji from Noto Emoji. That's only 5 icons. If you use fonts, you'd have to load 3 fonts with their stylesheets. That's a lot of resources that slow down your pages. With Iconify all you need to include is one script that is about 21kb in size and use same syntax for all icons:
<span class="iconify" data-icon="ic-baseline-face"></span>
<span class="iconify" data-icon="ic-baseline-arrow-drop-down"></span>
<span class="iconify" data-icon="ic-round-sync-disabled"></span>
<span class="iconify" data-icon="fa-solid:home"></span>
<span class="iconify" data-icon="noto:cat-face"></span>
Iconify will load only those 5 icons out of over 40,000 icons. It will be done in fraction of second. Fast and efficient.
To make that happen Iconify uses complex API. Such fast dynamic response is not possible using simple hosting solutions, it requires complex solution.
from iconify.
Unlike fonts, icons are not included with JS file because there are over 40,000 icons. Only icons that are used on page are loaded.
Icons are served from public API.
You add script on page, script scans document for icon placeholders, then it downloads used icons from API and replaces placeholders with SVG.
To make things as fast as possible, API is served from several servers placed in different regions. Also for additional security it is routed through CloudFlare servers. For Russia closest servers would be in Frankfurt for western part, in Tokyo for eastern part. Due to Russia being rather far from nearest servers, loading speed would probably be around 200-300ms. It is still almost instant. Loaded icons are cached in sessionStorage, so that small latency affects only first page load.
CloudFlare is used by many many services, so I don't see how RosKomNadzor would block them. That would be like blocking massive chunk of internet.
You can completely avoid using API. There are several options, which I've made for people that prefer to keep everything on their own servers. Everything is open source:
-
Host your own API. I wrote a tutorial for that: https://iconify.design/docs/api-hosting/
-
Bundle icons used on website, so Iconify script doesn't need to load them. See https://iconify.design/docs/icon-bundles/
-
If you are writing React application, use React component. It doesn't rely on API, instead it bundles used icons during build process. See https://github.com/iconify-design/iconify-react
As for purifyCss, Iconify doesn't work like fonts. There is no CSS. Placeholders are replaced with SVG, not with pseudo elements.
from iconify.
The functionality is impressive. Many thanks for the detailed explanation.
from iconify.
Related Issues (20)
- svelte OfflineIcon broken with 3.1.6 HOT 2
- Typescript complains HOT 9
- api changes HOT 5
- width and height is not matched correctly when setting with a decimal HOT 1
- Icon collection request: Bitcoin Icons HOT 3
- Package `@iconify/icons-material-symbols-light` not published to npm HOT 1
- Iconify on Svelte problem - Cannot find module HOT 1
- ✨ Align syntax for icons HOT 2
- Penpot integration HOT 2
- bug[React]: Icon Component does not render icon on first render when using `loadIcons` to preload HOT 5
- iconExists() not working on deployed site HOT 2
- [DEP0166] DeprecationWarning HOT 10
- [BUG] Deprecation Warning on Nuxt.js build due to package.json export HOT 2
- Workerd SSR issues HOT 1
- Hey I found an Issue !! HOT 2
- iconify/vue 使用addCollection加载图标集 还会向远程服务器发起请求吗 我想就将图标集打包到项目中
- Release of icons with android library HOT 8
- @iconify/tailwindcss redundant code HOT 16
- 在uniapp中怎么使用unocss+iconify实现图标展示啊? HOT 1
- 在uniapp中显示不出来图标 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from iconify.