typefaces

NPM packages for Open Source typefaces

Github星跟踪图

Typefaces

NPM packages for Open Source typefaces — making it easier to self-host
webfonts.

https://www.bricolage.io/typefaces-easiest-way-to-self-host-fonts/

Why

  • Self-hosting is significantly faster. Loading a typeface from Google
    Fonts or other hosted font service adds an extra (blocking) network
    request
    . In my
    testing
    , I’ve
    found replacing Google Fonts with a self-hosted font can improve a
    site’s speedindex by ~300 miliseconds on desktop and 1+ seconds on 3g.
    This is a big deal.
  • Your fonts load offline. It’s annoying to start working on a web
    project on the train or airplane and see your interface screwed up
    because you can’t access Google fonts. I remember once being in this
    situation and doing everything possible to avoid reloading a project as
    I knew I’d lose the fonts and be forced to stop working.
  • Go beyond Google Fonts. Some of my favorite typefaces aren’t on
    Google Fonts like Clear Sans, Cooper
    Hewitt
    ,
    and
    Aleo.
  • All web(site, app) dependencies should be managed through NPM whenever
    possible. Tis the modern way.

What

Each typeface package ships with all the necessary font files and css to
self-host an open source typeface.

All Google Fonts have been added as well as a small but growing list of
other open source fonts. Open an issue if you want a font added!

How

Couldn’t be easier. This is how you’d add Open Sans.

npm install --save typeface-open-sans

Then in your app or site’s entry file.

require("typeface-open-sans")

And that’s it! You’re now self-hosting Open Sans!

It should take < 5 minutes to swap out Google Fonts.

Typeface assumes you’re using webpack with loaders setup for loading css
and font files (you can use Typeface with other setups but webpack makes
things really really simple). Assuming your webpack configuration is
setup correctly you then just need to require the typeface in the entry
file for your project.

Many tools built with webpack such as
Gatsby and Create React
App
are already
setup to work with Typefaces. Gatsby by default also embeds your CSS in
your <head> for even faster loading.

If you’re not using webpack or equivalent tool that allows you to
require css, then you’ll need to manually integrate the index.css and
font files from the package into your build system.

Alternatives without Webpack

Adding other fonts

The easiest way to find out if your favorite typeface is supported is by
searching on NPM or in the packages directory in this repo.

I’d love to see every open source font on NPM! Open an issue if a
favorite typeface of yours is missing. I’ve programmatically published
all fonts from Google Fonts and am planning on doing the same with fonts
hosted on FontSquirrel through their
API
.

Other ideas to explore

  • Add subsetted version of every font.
  • Initially I’ve just added support for the Latin version of fonts.
    Would love to hear ideas for how to support other languages. Perhaps
    additional css files e.g. require('open-sans/greek.css')?
  • Ship fallback css helpers — figuring out your fallback css isn’t
    particularly easy. Perhaps there’s a way to automate this. E.g. if
    you’re using typeface X at fontsize Y with fallback font Z, here’s a
    function to generate the fallback css.
  • Explore futher optimizations for loading fonts.
    https://www.zachleat.com/web/comprehensive-webfonts/ has a long list.
    Most require painful per-project scripting. What if the best strategies
    could be automated?

主要指标

概览
名称与所有者KyleAMathews/typefaces
主编程语言CSS
编程语言CSS (语言数: 2)
平台
许可证
所有者活动
创建于2016-11-02 02:50:29
推送于2023-09-09 15:09:22
最后一次提交2023-09-09 08:09:22
发布数81
最新版本名称v1.1.15 (发布于 2020-12-16 21:50:02)
第一版名称v0.0.1 (发布于 )
用户参与
星数2.6k
关注者数23
派生数92
提交数233
已启用问题?
问题数191
打开的问题数105
拉请求数7
打开的拉请求数21
关闭的拉请求数13
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?