Saving the Internet 2000TB a Day: Fixing Font Awesome’s Fonts
pixelambacht.nl
pixelambacht.nl
It's all based on coming up with two numbers that when multiplied say that this resource is downloaded 73 billion times a day. That's 20 times / day for every internet user (even those using it on a 2G connection once a year). Given a reasonable caching period of 1 month, that'd mean the average user visits 600 different sites a month. That seems like much more than one would expect.
Or to look at it another way, global IP traffic is apparently estimated at 72000 PB/month. That's 2400PB/day. This font alone would then be accounting for 0.3% of all internet traffic, or 1% of all non-video traffic. Again, that's a very high number.
But at least it doesn't appear to be a totally impossible number either, just an awfully implausible one.
73,000,000 sites * 1000 visitors * 10 bytes / 1024^3That reminds me, I want to browse the site on lynx and see what happens...
ps. I can't use any of your examples. I use a portrait orientated screen which causes the examples list to go below the example. Hovering over them causes the example to change, which changes the height of the area, which forces a hover event on another item in the list as it gets pushed up/down which repeats the process until the height is either too short or too tall for me to be hovering an item in the list.
Consider making it a .onClick() event after a certain screen size? :)
E: Woah! Just realized you're the same kalid behind betterexplained. Another really awesome resource. :)
Glad you're enjoying betterexplained too ;).
I love instacalc.
[1] I mean that in the most endearing way.
use `fa.css` and if you want the expanded one for development, then you could have `fa.[max|debug|whatever].css`
Most sites are obscure, and rarely get any visitors at all. Maybe 10 a month, or none.
Popular sites that receive a lot of traffic are also visited very frequently by the same user, so the font will be in the cache.
In addition, plenty of sites use a CDN for fontawesome.
I guess that number is off by several orders of magnitude.
Interestingly the number of active sites hasn't materially changed in 5 years, but host names have skyrocketed.
[0] https://news.netcraft.com/archives/category/web-server-surve...
> If each day 73 million websites serve the Font Awesome WOFF to an average of a thousand visitors who don’t have these fonts in the browser’s cache...
This assumption that they don't have the fonts cached is only sensible if each user is unique. But that means that we have 73 BILLION unique users.
Another thing I'm super excited about is stray points in vectors. We found some new tools for Illustrator that make this a LOT easier and will have a very real impact on bandwidth as well.
Super fun.
Edit: Fixed wording for clarity.
But, isn't subsetting going to result in users now caching your subset instead of a cached copy of everything? I would think that does more harm than everyone grabbing a fully cached copy once from a cdn.
On the other hand, it seems that FA themselves are building a CDN with subsetting, so they could in fact provide those shared subsets. Unfortunately (but understandably) it's paid, so most of us can't use it.
For starters, leveraging caching via a common CDN pretty much requires everyone to be using a single version from a single CDN. If you can't agree on that, then every time a new version comes out the web is split and the caching doesn't work, and every time someone decides to use another CDN (or someone provides a new one) the group is split again.
But then split that across all the fonts, formats, and compression schemes available and you'll see that the chance that a visitor has seen that font, at that version, from that CDN, using that compression scheme, in that format at any point in the past EVER is actually significantly smaller than you'd think.
Which brings us into the next point. Even if you've seen it before, the chances that you'll have it cached is pretty small. Browser caches are suprisingly small in the grand scheme of things, and people tend to clear them more often than you think. Add in privacy browser mode and "PC cleaner" programs and the average person's caches lasts much shorter than at least I expected it to.
But even worse are mobile caches. IIRC older android had something like a 4MB cache!!! And until very recently safari had something like a 50mb limit (and before that didn't cache ANYTHING to disk!). Now it's better, but you are still looking at a few hundred MB of cache. And with images getting bigger, big GIFs being common, huge amounts of AJAX requests happening all the time in most web pages, you'll find that the browser cache is completely cycled through on a scale of days or hours not weeks or months.
IMO it's at the point where the "dream" of using a CDN and having a large percentage of your users already have the item in their cache isn't going to work out, and you are better off bundling stuff yourself and doing something like "dead code elimination" to get rid of anything you don't use. And that method only becomes more powerful when you start looking at custom caching and updating solutions. A few months ago I saw a library that was designed to only download a delta of an asset and store it in localstorage so updates to the application code only need to download what changed and not the whole thing again. Sadly I can't seem to find it again.
My employer manages like $20k devices. I betcha we spend 5 figures annually on this crap.
installing a ton of fonts up front takes a pretty significant amount of space, installing a subset for their language/preference or letting the user manage it makes it VERY easy to fingerprint users based on what fonts they download, and doing any kind of cross-origin long-term caching is a security nightmare as it lets you begin to map out where a user has been just based on what they download.
It solves a problem that people other than web designers care very little about, but costs me money and creates a slew of other problems...
Personally, I wish it was easy to just turn off!
You could compare it with http/2: If you do a survey, you won't find many people even knowing it. That doesn't mean it's useless to them.
On 3G or shaky Wi-Fi, I've regularly given up on browser tabs because all I see is an empty page, even after half a minute of loading and when most images have finished downloading. (Maybe other browsers are better than Safari, but I won't switch just to see prettier fonts.)
Most people already have attractive, readable fonts installed on their computers, which are likely either sensible defaults, or configured for specific reasons (e.g. minimum size to deal with eyesight). Web pages that render as blank white space for awhile, or briefly tease me with text before blanking it out, give me a much more negative impression than ones that simply render in my chosen default fonts.
I've been blocking web fonts for a while, and it feels like I have to whitelist one site out of three because it depends on icon fonts.
All this common web stuff that is distributed by several CDNs (as well as separately by individuals) really suggests to me that there should some browser feature like `<script src="jquery.min.js" sha256="85556761a8800d14ced8fcd41a6b8b26bf012d44a318866c0d81a62092efd9bf" />` that would allow the browser to treat copies of the file from different CDNs as the same. (This would nicely eliminate most of the privacy concerns with third-party jQuery CDNs as well.)
This not only solves the CDN issue but it also solve the issue of having to rename the files manually everytime someone do a change. It just makes caching that much saner.
If you see a script tag with the URL bank.com/evil.js, the browser shouldn't assume that the bank is actually hosting evil.js. Even if the hash matches, the content might not be there.
The bank might be using a content security policy to minimize the damage that an XSS attack can do. It only allows script tags from the same origin. However, now an attacker just needs to load evil.js with a particular hash into the cache, and they can create the illusion that the site is hosting it, without having to hack the server to do so.
So to take it to a bit of a rediculous (but still possible) point, I could probably guess what your HN user-page looks like to you. So from there I could serve that in an AJAX request to all my visitors with this content-based hash and if I get a hit from someone, I can be pretty damn sure it's you.
And that only really solves one or 2 of those issues. The versioning, compression schemes, formats, number of fonts, and sizes of browser caches will still cause this system's cache to be a revolving door, just slightly more effective.
And as for the security concerns of using a CDN. Subresource-integrity (which someone else here linked already) allows you (you being the person adding the <script> tag to your site) to say what the hash of the file you expect is, and browsers won't execute it if it doesn't match. So that lets you include 3rd party resources without fear that they will be tampered with.
[1]: https://developer.mozilla.org/en-US/docs/Web/Security/Subres...
https://hillbrad.github.io/sri-addressable-caching/sri-addre...
Solution: Using a sha256="..." attribute should only allow you to access files that were initially loaded with a tag that has a sha256 attribute, and this attribute is only used for resources the developer considers public.
It's not. Because does this hurts page load times.
You are having to create a new, cold, TCP connection to go fetch 50-100KB of CSS/JS/whatever from some random server. Which even in HTTP/1.1 is usually slower than just bundling that into your own CSS/JS/Whatever. HTTP/2 makes it even more so.
Just store and serve these things yourselves.
Another option: find the most-used icons or combinations. Group them.
Another option: similar to nandhp, get a hash of the font selection and name the file so. There's a very good chance a nearby proxy has that combination stored already.
Disk is cheap. Particularly disks that you don't pay for like your users' disks.
[1]: Combination of security reasons and unnecessarily coupling apps to the public internet.
I saw a talk by someone from Smashing Magazine where they basically did this for a subset of their WebFonts (downloading the entire font asynchronously afterward), then they cached their WebFonts in LocalStorage, but it seems like it make even more sense for an icon font where you're using a very small subset.
Unfortunately it is still a bit big. Simply converting it to SVG would probably be smaller. I'd welcome a simple tool that does that!
1. Open fontawesome-webfont.svg in a text editor.
2. Find the glyph you want to use.
3. Copy it into a new file.
4. Add boilerplate[1] to new file.
5. Change the <glyph> tag to a <path> tag.
6. Add the attribute `transform="scale(0.1,-0.1) translate(0,-1536)"`
7. Open the file in Chrome and see your SVG.
[1] boilerplate:
<?xml version="1.0" encoding="utf-8"?>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 179.2 179.2">
{glyph goes here}
</svg>
[Example]Starting with the following glyph:
<glyph glyph-name="home" unicode="" horiz-adv-x="1664" d="M1408 544v-480q0 -26 -19 -45t-45 -19h-384v384h-256v-384h-384q-26 0 -45 19t-19 45v480q0 1 0.5 3t0.5 3l575 474l575 -474q1 -2 1 -6zM1631 613l-62 -74q-8 -9 -21 -11h-3q-13 0 -21 7l-692 577l-692 -577q-12 -8 -24 -7q-13 2 -21 11l-62 74q-8 10 -7 23.5t11 21.5 l719 599q32 26 76 26t76 -26l244 -204v195q0 14 9 23t23 9h192q14 0 23 -9t9 -23v-408l219 -182q10 -8 11 -21.5t-7 -23.5z" />
We end with:
<?xml version="1.0" encoding="utf-8"?>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 179.2 179.2">
<path transform="scale(0.1,-0.1) translate(0,-1536)"
glyph-name="home"
unicode=""
horiz-adv-x="1664"
d="M1408 544v-480q0 -26 -19 -45t-45 -19h-384v384h-256v-384h-384q-26 0 -45 19t-19 45v480q0 1 0.5 3t0.5 3l575 474l575 -474q1 -2 1 -6zM1631 613l-62 -74q-8 -9 -21 -11h-3q-13 0 -21 7l-692 577l-692 -577q-12 -8 -24 -7q-13 2 -21 11l-62 74q-8 10 -7 23.5t11 21.5 l719 599q32 26 76 26t76 -26l244 -204v195q0 14 9 23t23 9h192q14 0 23 -9t9 -23v-408l219 -182q10 -8 11 -21.5t-7 -23.5z" />
</svg>
The `unicode` and `glyph-name` attributes can be removed. fa2svg f015 Think "I want that glyph" and then it's just there!This converts the icons to either svg or png in whatever color you want, in any size you want.
http://olegkikin.com/badge2_cleaned.svg
And it GZips better as well (4793 -> 2120).
I opened it in Inkscape, converted the text to path. Then ran it through SVGCleaner.
You can also do manual simplification in Inkscape (Ctrl + L) till the quality starts to degrade. This lets you reduce things even further:
http://olegkikin.com/badge3_cleaned.svg
3516 bytes, 1726 GZipped.
(If you want, you can also submit a patch in https://github.com/badges/shields.)
Also, merging path elements together helps.
For example, here's the logo in 1952 bytes: http://pastebin.com/YYBpWsDE
And I'm sure there's further room for manual reduction, maybe by switching between strokes/fills and further cleaning up the paths.
(It would be cool if someone were to work on an automated system for doing this kind of simplification. But I have a feeling that it's difficult find a general technique that will work across SVG hierarchies, like scaled/rotated groups, etc.)
101K 9 Dec 18:30 with.css
99K 9 Dec 18:31 with.min.css
73K 9 Dec 18:31 with.min.css.gz
6.8K 9 Dec 18:30 without.css
5.2K 9 Dec 18:31 without.min.css
1.8K 9 Dec 18:31 without.min.css.gz
Although this might be true:> …72k, which is not much bigger than the CSS without the fonts + the fonts separately.
The issue here is that CSS is a render-blocking resource and fonts are not; ergo you’ve increased render-blocking assets from 1.8K to 73K, meaning the user has to download 4056% more bytes before they get to see anything at all. Base64 encoding assets is usually a huge anti-pattern. You’d be better off moving those fonts back out into separate requests.
I hope this comment is taken in the spirit it’s intended: I like making the internet fast :)
Have a great weekend!
(If you’re interested in further reading, look up anything to do with the critical rendering path.)
One advantage of embedding the fonts is that it eliminates FOUT. If the fonts were split out, once the fonts were loaded, the page would need to be re-rendered anyway. I don't see much practicality of rendering an already light page if it's going to be re-rendered differently quickly after.
By embedding the fonts, I've optimized for latency in downloading fewer files over HTTP1. Even a 2k CSS and 20k-ish font are hardly worth the cost in opening the connections; a 73k all-in-one is more efficent. Let's assume a reasonable 8mbit connection and 50ms RTT.
To download the 72k CSS on a new connection (because it's early in the page load), that takes 100ms to establish TCP and HTTPS handshake, and 122ms to download the 72k embedded font CSS, total: 222ms (at least, not including processing overhead).
For the split version: 100ms for handshakes, and 52ms for the 2k CSS transfer. Here, the browser might keep it open to download one (the headline font) (negligible load time for a open connection), and open another connection for the body text font. (the third monospaced font is rarely used.) The open one would download one 23k font in 73ms. The other connection (in parallel) will take 100ms for handshake, and 73ms for another 23k font. total: 325ms (at least, not including processing overhead).
For higher bandwidth connections, bigger files make even more sense. For split files to truly win, latency will need to be impossibly low, which for the hosting from my apartment basement (even on 150mbit fiber), is impossible.
Even though it's render blocking, browsers will continue loading other assets anyway. A mostly (if not fully complete) page will show the first time, often within a second on wired connections.
> I hope this comment is taken in the spirit it’s intended: I like making the internet fast :)
Yup. Me too!
> Let's assume a reasonable 8mbit connection and 50ms RTT.
This is a huge assumption; you’ll be neglecting almost all of your mobile users there. But! Optimise for your use-case, of course.
If you’re self hosting your fonts I would leave them external, `preload` them, and use the preferred `font-display` mechanism to deal with (or elimiante) FOUT and/or FOIT. That’s your extra connections taken care of, and we’ve moved fonts back off of the critical path :)
I think what we’ve both hit upon here is the fact that browsers need to decide on a standard way of handling FOUT/FOIT. Leaving pages blank for up to 3s (or in Safari’s case, indefinitely) would completely eliminate the need to try and circumvent it by base64 inlining :(
With base64 you are also downloading all of them all the time.
Or and sorry to say cause I like FA, screw them and see if Apple/MS/Google can have an open standard icon font that doesn't suck.
https://admin.fedoraproject.org/pkgdb/package/rpms/fontaweso...
If that's too steep for you, maybe a browser extension would be a good middle ground.
I can think of a few [1][2][3] examples just off the top of my head.
[1] https://developers.google.com/speed/libraries/ [2] https://www.jsdelivr.com [3] https://cdnjs.com
otf 110KB
eot 102KB
svg 157KB
ttf 102KB
woff 96.1KB
woff2 75.8KB
All appear to be using gzip in headersAre you using the same URLs I posted?
Here is a codepen if someone else wants to try OTF results
It seems very strange that the size reported by the parent is varying. Why would it do that? Are they all the same file or different ones?
There are a number of tools that will optimize svg files for size like svgo. Output straight from Illustrator, for example, has a lot room for improvement. I also usually end up hand-tweaking for things like removing the full style and doing that in my site's CSS.
What I think is really still needed are more options besides Illustrator for generating svg content. Yes, Inkscape is overall ok but is lacking in setup ease and genera speed.
There a number of programs that are so close to doing what is needed and then won't save or export an svg. Pixelmater, looking at you.
- You're more likely to hit aligment/layout issues because you're using a tool designed for text to render pictures
- The character codes used are textual information but have no semantic meaning (this can be addressed by using ligatures or characters in the private unicode range)
- Adding more icons requires regenerating the font
- Using a subset of icons requires regenerating the font
- Font authoring is non-trivial and requires much more specialized tools and knowledge when compared to SVG
- You need to ship the font in various formats (TTF, OTF, WOFF, WOFF2)
- It's not easy to animate icons, or include colors or transparency
- By now SVG support is sufficiently widespread, so the original rationale for using font icons no longer applies
None of these, except maybe the rendering quality, are deal breakers. Workarounds and counterarguments do exist. And SVG does have some disadvantages too (e.g. parsing overhead, filesize, memory consumption)
I personally side with using SVGs currently. As technology progresses, I might definitely reassess my view.
Your argument about desktop apps isn't very good because people can (and do) prevent desktop apps from doing certain things and accessing various stuff, like web cams, the microphone, system directories, the internet, etc. If my text editor breaks because it can't access my webcam, I'd say it's a serious problem.
It isn't just bloody-minded fanatics who object to web fonts.
(full disclosure: I am a bloody-minded fanatic and also object to web fonts)
Blocking web fonts usually does not noticeably degrade a site's usability or functionality. Icon fonts are the exception. I've learned that a question mark in the upper-right corner is usually a site's menu, except when it's the search function. I don't think that this level of breakage is comparable to what happens when JavaScript is disabled, since many sites just break completely without scripting.
Saying "Screw it, More people died in other places" is missing the point. The article even admits this is not the #1 place to optimize... but that doesn't mean you should scoff at it.
>How Font Awesome 5 Became Kickstarter’s Most Funded Software Project
I checked their kickstarter, however. >35,550 backers pledged $1,076,960 to help bring this project to life.
Pillars of Eternity, most assuredly software, was a kickstarter I backed. Their campaign page reads to this day:
>73,986 backers pledged $3,986,929 to help bring this project to life.
Why make up such a shitty lie? Does it matter if you have the longest John in the pub? Is this something USA specific down the American Dream/Meritocracy/Competitiveness axis? I find most European projects to be more modest about these things.
No hate please! None intended here. It just feels weird to me.
https://www.kickstarter.com/discover/categories/technology/s...
Pillars of Eternity is in the Video Games category and so isn't counted as Software.
http://bitsup.blogspot.de/2016/05/cache-control-immutable.ht...
But one nice side-effect of changing it to svg versions is that our clients are now loading icons on demand and only the ones being used in the app, as opposed to the whole web font.