frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

fp.

Open in hackernews

How to self-host a web font from Google Fonts

https://blog.velocifyer.com/Posts/3,0,0,2025-8-13,+how+to+self+host+a+font+from+google+fonts.html
39•Velocifyer•1h ago

Comments

damieng•1h ago
Even better download it, subset it then base64 encode it into your CSS for zero FOUC.

https://damieng.com/blog/2021/12/03/using-variable-webfonts-...

olivia-banks•56m ago
Couldn't this increase FOUC? At least before you could load in your style-sheet before the font, but if you embed the font inside you get no styling at all until it can fetch all of the data, correct
erikpukinskis•54m ago
Not if the styles + fonts are all in the <head>?
booi•3m ago
wouldn't the problem be the fonts are basically in every single request and uncacheable then?
lelandfe•32m ago
The default method of loading CSS fonts has no FOUC (`font-display: auto` is `block`), so no need to base64 encode.

`font-display: swap` introduces FOUC but with a quicker first paint, which some find preferable (in Lighthouse terms, you're trading CLS for FCP).

If you're base64'ing with the intent of loading the font file sooner, just use:

     <link rel="preload" href="/assets/my-font.woff2" as="font" type="font/woff2" crossorigin>
This has the downside of loading a WOFF2 file for all browsers, even ones that don't support WOFF2. These days, ~all browsers support that format: https://caniuse.com/woff2
jraph•9m ago
If you do this, you make the page slower to load for people blocking external fonts.

Not doing it is also nicer for people with slow/unreliable network access, where they can block fonts, or even if they don't block them, can access your page more quickly and have a render without the custom font.

dewey•1h ago
And once you use these fonts, make sure to not use blue as link color with a dark background, so that your readers can actually read your content too ;)
gethly•1h ago
It's like people are rediscovering CSS from 20 years ago.
rs186•1h ago
I tried to do something similar myself once but quickly gave up. I decided to just slap that line Google gave me in the web page.

I get why it is "better" -- CDN, optimized for browser blah blah. But I really wanted to host it myself, because 1) it's my website 2) I don't want every visitor to send a piece of information about themselves to Google just to get some fonts.

But apparently Google is not motivated to offer such a solution, at all.

trnglina•1h ago
What made you give up? As the article describes, self hosting fonts is as easy as making the static font files available and then adding a few lines of CSS. What solution would you want Google to offer?
rs186•23m ago
I needed to figure out exactly which files need to be there, and I needed to understand what's happening in that CSS file. I vaguely remember seeing different content for the CSS file in different browsers.

At that time it would take me more than a few minutes (which was what I had), and seemed a rabbit hole. I decided not to pursue that.

cornedor•1h ago
Since caches are no longer shared between pages, it actually is often better to self host your fonts than rely on public CDN’s. Makes it even weirder that Google does not offer a simple solution to self host fonts.

https://dev.to/rstacruz/public-cdns-arent-useful-anymore-2b6...

OskarS•1h ago
Google Fonts lets you just download the font, right? So what's the problem with self-hosting them? They're not encrypted or anything. Like, I'm not sure what else you would want Google to do.
dawnerd•1h ago
It’s like we’ve taken a step back and people forgot how the web used to be built. I’ve also seen someone ask how you use JavaScript if you don’t have a preprocessor like webpack.
Velocifyer•1h ago
Google fonts download button gives you a TTF file and not a WOFF2 file so you have to read the CSS to get the WOFF2 file.
darrenf•50m ago
Or you use Google's own TTF <-> WOFF2 converter tools: https://github.com/google/woff2 [0]

I have very recent -- like, 2 weeks ago -- successful experience of using these, since I wanted to distribute a WOFF2 as part of a browser extension.

[0] edited to add - you don't have to build it, you can get it from homebrew https://formulae.brew.sh/formula/woff2 or an Arch package https://archlinux.org/packages/extra/x86_64/woff2/ and presumably other distros

cornedor•13m ago
Any idea if the woff2 files served by Google are the same? Or that they maybe are more optimized for web?
rs186•22m ago
It's not a single file with a simple line of CSS like in the old days. It's a bunch of files, so you need to make sure you do have all the files and understand how exactly these come together.
valadaptive•54m ago
I was going to wait to post this until I've finished the CLI and documentation, but this seems like a relevant time to plug my web font subsetting/self-hosting tool: https://glypht.valadaptive.dev/

It lets you pick from the Google Fonts catalog, and comes with various options for further reducing the fonts' sizes if you're as obsessed with webpage size as I am.

ksymph•14m ago
This is fantastic! I was recently trying to prepare a number of fonts for web use and there was a lot of friction -- each part of the process needed a different tool, each with its own weird quirks. Glypht looks to have everything in one place without any extraneous stuff or legacy cruft. I didn't even know it was possible to make a subset of weights for variable fonts. I'll be making thorough use of this, thank you!
SigmundurM•51m ago
I use google-webfonts-helper (https://gwfh.mranftl.com/fonts) to get google fonts
wonger_•12m ago
Just found out about this recently. So lean and snappy compared to the default interface.
WebBurnout•50m ago
FontSource releases all of google fonts and more as NPM packages: https://fontsource.org
filt•12m ago
This is the way to do it!
Imustaskforhelp•1m ago
this is really fascinating considering that they package it as a npm package which is then used by jsdelivr which is essentially a free really low latency sponsored/(essentially operated?) by cloudflare and fastly etc.

I just checked and jsdelivr has had like 300 billion requests past month and over 16,813 TB

Really fascinating stuff. I will try to use this from now on! (earlier I was thinking of using something like coollabs.io but I checked its code and I see that the fonts are served through something like bunnycdn from coollabs side which is cool but still)

Honestly, what other things would be better off packaged as npm packages as I never thought that packaging fonts as npm package should make so much sense but here we are!

Bookmarked!!

jrm4•45m ago
Okay, so as something of an old-timer:

WAT

Like, as someone who teaches IT -- an article like this getting this high in hacker news is just very wild to me. Which is to say:

The answer that ought to be obvious to this crowd is "Download it and link to it in your HTML/CSS in your local html directory."

Now, I'm aware that at least part of the reason this isn't the extremely obvious answer has to do with some friction on the downloading as well as perhaps cdn stuff.

But still; wow. As far as we have gotten in some ways, we've clearly lost A LOT of simplicity that shouldn't be -- but apparently -- really difficult to recover.

freedomben•34m ago
I had the same thought. Makes me think we're getting old and the old ways of the web just aren't known as widely anymore.

I've had to do this several times in the past because the customer firewall blocks google domains, and it never required a second thought. The only question I had was around the legality of doing so (which I checked on). Once I verified that, it was about 2 minutes of wget (or curl) the file down, stick in a static web server, and update the links in the HTML page and Bob's your Uncle

jrm4•24m ago
I'm a lawyer so an example something I WOULD NEVER SAY IN EARNEST, but I perhaps would if I wasn't might be:

"And perhaps even the idea of having to think about the legality of such things is part of the problem, I can remember when we'd just DO IT."

:)

jraph•12m ago
And it's legal because Google Fonts hosts open source fonts exclusively :-)
jraph•16m ago
> an article like this getting this high in hacker news is just very wild to me

It might be because it's a "You should host web fonts from Google Fonts yourself" in disguise. The technical "How to" is almost not the important part here :-)

It may give some pause to web devs who hotlink to google here on HN without much thoughts and make them consider doing it differently next time.

I suspect many people upvoting it are doing it for this. Maybe upvotes here might actually mean "Please host Google Fonts yourself".

hluska•15m ago
I’m old too, but have a different take on this type of content. Part of being old was the privilege of coming up within an industry when everything was documented and most things were searchable. IRC was the only walled garden and it was reasonably common for teams to turn their frequently asked questions into web content.

So things got to become common sense for us because it was easy to get overwhelmed in information on why it should be common sense. The web has changed dramatically - there is a lot of content in Discord servers and it’s rare for frequently asked Discord questions to turn into web content. Common sense isn’t as wide ranging, but that’s been replaced by extreme specialty knowledge.

I see this a lot in software companies when build tools crap out. Younger developers have much more specialized knowledge on the build tools and can outwork me when everything is on the happy path. Off the happy path, all the general bits and pieces we picked up through osmosis back in the day become very helpful.

I’m glad that articles like this are being promoted. This plumbing type knowledge will be useful many many times over the course of a career. Not everything has to be aimed at me to be good, you know?

Propelloni•4m ago
I'm old,too. I remember when the default fonts of the web browser were good enough. Matter of fact, they still are, but today I, as a user, have to jump through some easy hoops to get the font of my choice ;)
magicalist•1m ago
100% agreed.

> Now, I'm aware that at least part of the reason this isn't the extremely obvious answer has to do with some friction on the downloading

Maybe it's changed, but I remember it always being very upfront and easy to download.

The instructions in this article are also silly.

Yes, click the "Get font" button as instructed, but then click "Download all" instead of "Get embed code" and then doing all those extra steps. You'll get a zip file with everything in it.

dktalks•43m ago
What benefits are you getting from this? I mean have you built an entire CDN to cache the fonts so that your server does not have to download it every time a new page is loaded? I understand self-hosting for your own servers, but for a website this is overkill.
ameliaquining•36m ago
Hotlinking Google Fonts leaks your visitors' IP addresses to Google. This bothers some people.
JimDabell•22m ago
It’s more than just “bothers people”. Some jurisdictions consider this to be leaking PII without consent and will issue fines if you don’t self-host or ask permission. For example:

https://www.theregister.com/2022/01/31/website_fine_google_f...

Google Fonts has an open issue that is three years old here, with no response from Google:

https://github.com/google/fonts/issues/5537

brycewray•6m ago
Also:

https://github.com/google/fonts/issues/1495

freedomben•31m ago
For me the biggest benefit is that my customer doesn't have to whitelist a google endpoint to use our website. Secondary benefit is being in control of downtime and/or updates (though the secondary benefit on it's own is nowhere near enough to justify self-hosting to me, but for some people it might be)
mlunar•28m ago
Not the author, but last time I checked (3y ago), the fonts CDN was surprisingly slow, like hundreds of milliseconds of latency.

As the website I was optimizing was selfhosted, also selfhosting the font had a noticeable effect on the page load time. See https://github.com/SmilyOrg/photofield/commit/12352667c01624...

I'm not sure what you mean with the rest of the comment though, it's a very small change and it gets cached by the browser like other static assets, so I'm not sure what is the overkill here.

Velocifyer•10m ago
I have Cloudflare and I have the TTL set to 10 years
nick_•38m ago
But doesn't Google serve a different font depending on the User Agent string? IIRC, it serves fonts based on your OS and browser so that differences in rendering implementations are corrected for.
thm•37m ago
Article forgot to mention variable fonts, so you should do something like

  @supports (font-variation-settings: normal) {
      body {
          font-family: "V-Font", regular fonts...;
      }
  }
Velocifyer•18m ago
The method in the article just uses the Google Fonts CSS but with the paths modified
tmdetect•35m ago
I used to use Google fonts a fair amount, but why do I need to download a font when my browser/os already have a reasonable amount of good ones? Engineer aesthetic/logic maybe?

I had to go digging for it again and I've now bookmarked it, but this website/repo has some nice examples: https://modernfontstacks.com/

Velocifyer•14m ago
Some of my readers don't have Noto Sans (the best font) and Fira Code (the best font for coding) installed.
aleyan•15m ago
The view warrant canaries[0] link on the bottom of the page goes to a cloudflare 502 page. Bitrot is indistinguishable from subpoena, but neither is a good indicator.

[0] https://files.velocifyer.com/Warant%20canaries/

Velocifyer•8m ago
I fixed it
rambambram•15m ago
Everything old is new again. ;) Jokes aside, I think it's good to serve the fonts directly, there's no need to do a 'phone home' roundtrip to google only to present some fonts.

And while you're at it (and you use multiple fonts), you might as well use CSS's font-face to harmonize the different fonts a little. Fonts with the same size might look bigger or smaller to the eye, depending on thickness of the lines and other font styles.

Hosting a website on a disposable vape

https://bogdanthegeek.github.io/blog/projects/vapeserver/
458•dmazin•3h ago•111 comments

Launch HN: Trigger.dev (YC W23) – Open-source platform to build reliable AI apps

36•eallam•1h ago•18 comments

CubeSats are fascinating learning tools for space

https://www.jeffgeerling.com/blog/2025/cubesats-are-fascinating-learning-tools-space
70•warrenm•2h ago•14 comments

Programming Deflation

https://tidyfirst.substack.com/p/programming-deflation
46•dvcoolarun•2h ago•24 comments

How big a solar battery do I need to store all my home's electricity?

https://shkspr.mobi/blog/2025/09/how-big-a-solar-battery-do-i-need-to-store-all-my-homes-electric...
67•FromTheArchives•3h ago•109 comments

RustGPT: A pure-Rust transformer LLM built from scratch

https://github.com/tekaratzas/RustGPT
266•amazonhut•6h ago•117 comments

Removing newlines in FASTA file increases ZSTD compression ratio by 10x

https://log.bede.im/2025/09/12/zstandard-long-range-genomes.html
174•bede•3d ago•65 comments

PayPal to support Ethereum and Bitcoin

https://newsroom.paypal-corp.com/2025-09-15-PayPal-Ushers-in-a-New-Era-of-Peer-to-Peer-Payments,-...
95•DocFeind•2h ago•76 comments

Apple has a private CSS property to add Liquid Glass effects to web content

https://alastair.is/apple-has-a-private-css-property-to-add-liquid-glass-effects-to-web-content/
130•_alastair•1h ago•65 comments

Folks, we have the best π

https://lcamtuf.substack.com/p/folks-we-have-the-best
242•fratellobigio•9h ago•69 comments

Show HN: Daffodil – Open-Source Ecommerce Framework to connect to any platform

https://github.com/graycoreio/daffodil
22•damienwebdev•1h ago•2 comments

Language Models Pack Billions of Concepts into 12k Dimensions

https://nickyoder.com/johnson-lindenstrauss/
301•lawrenceyan•12h ago•97 comments

Show HN: I reverse engineered macOS to allow custom Lock Screen wallpapers

https://cindori.com/backdrop
41•cindori•8h ago•30 comments

The Mac App Flea Market

https://blog.jim-nielsen.com/2025/mac-app-flea-market/
159•ingve•9h ago•85 comments

Show HN: Semlib – Semantic Data Processing

https://github.com/anishathalye/semlib
25•anishathalye•2h ago•8 comments

Death to type classes

https://jappie.me/death-to-type-classes.html
75•zeepthee•3d ago•48 comments

Meta bypassed Apple privacy protections, claims former employee

https://9to5mac.com/2025/08/21/meta-allegedly-bypassed-apple-privacy-measure-and-fired-employee-w...
56•latexr•1h ago•21 comments

Pgstream: Postgres streaming logical replication with DDL changes

https://github.com/xataio/pgstream
36•fenn•4h ago•2 comments

A qualitative analysis of pig-butchering scams

https://arxiv.org/abs/2503.20821
146•stmw•12h ago•79 comments

A string formatting library in 65 lines of C++

https://riki.house/fmt
5•PaulHoule•39m ago•3 comments

Which NPM package has the largest version number?

https://adamhl.dev/blog/largest-number-in-npm-package/
133•genshii•13h ago•55 comments

Not all browsers perform revocation checking

https://revoked-isrgrootx1.letsencrypt.org/
76•sugarpimpdorsey•13h ago•61 comments

The madness of SaaS chargebacks

https://medium.com/@citizenblr/the-10-payment-that-cost-me-43-95-the-madness-of-saas-chargebacks-...
47•evermike•5h ago•67 comments

The Culture novels as a dystopia

https://www.boristhebrave.com/2025/09/14/the-culture-novels-as-a-dystopia/
34•ibobev•7h ago•54 comments

Creating a VGA Signal in Hubris

https://lasernoises.com/blog/hubris-vga/
6•lasernoises•1h ago•1 comments

Denmark's Justice Minister calls encrypted messaging a false civil liberty

https://mastodon.social/@chatcontrol/115204439983078498
353•belter•4h ago•222 comments

NASA's Guardian Tsunami Detection Tech Catches Wave in Real Time

https://www.jpl.nasa.gov/news/nasas-guardian-tsunami-detection-tech-catches-wave-in-real-time/
119•geox•2d ago•20 comments

Cory Doctorow: "centaurs" and "reverse-centaurs"

https://locusmag.com/2025/09/commentary-cory-doctorow-reverse-centaurs/
63•thecosas•3d ago•18 comments

Human writers have always used the em dash

https://www.theringer.com/2025/08/20/pop-culture/em-dash-use-ai-artificial-intelligence-chatgpt-g...
62•FromTheArchives•2d ago•79 comments

PythonBPF – Writing eBPF Programs in Pure Python

https://xeon.me/gnome/pythonbpf/
124•JNRowe•3d ago•28 comments