Git Product home page Git Product logo

Comments (3)

cyberalien avatar cyberalien commented on May 30, 2024 1

After reading that reply, I think I've overcomplicated it and didn't really answer question. So simple version:

  1. 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.

cyberalien avatar cyberalien commented on May 30, 2024

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:

  1. Host your own API. I wrote a tutorial for that: https://iconify.design/docs/api-hosting/

  2. Bundle icons used on website, so Iconify script doesn't need to load them. See https://iconify.design/docs/icon-bundles/

  3. 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.

andrey-helldar avatar andrey-helldar commented on May 30, 2024

The functionality is impressive. Many thanks for the detailed explanation.

from iconify.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.