• Stars
    star
    1,538
  • Rank 29,294 (Top 0.6 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 7 years ago
  • Updated about 1 month ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Command line tool to optimize your webfont loading. Aggressive subsetting based on your font use, self-hosting of Google fonts and preloading

subfont

NPM version Build Status Coverage Status

A command line tool to statically analyse your page in order to generate the most optimal web font subsets, then inject them into your page.

Speed up your time to first meaningful paint by reducing the web font payload and critical path to the font files.

Subfont will:

  • Automatically figure out what characters are used from each font
  • Warn you about usage of characters that don't exist as glyphs in your webfonts
  • Create an exact subset of used characters of each font
  • Generate web fonts in both woff2 and woff formats
  • Add preload hints for the subsets to reduce time to first meaningful paint
  • Add JS font loading for browsers without preload support
  • Give the subsetted fonts new names and prepend them in front of the original fonts in your font-family definitions (enables missing glyph fallback)
  • Async load your original @font-face declaring CSS at the bottom of your page, moving it off the critical path

A site before and after running subfont

Currently supported font services:

  • Google fonts
  • Local fonts

If you know of font services with liberal font usage licenses, open an issue and we'll add support for them

Installation

Get the basic CLI tool, which supports subsetting Google Fonts and optimizing all local fonts with preloading instructions:

npm install -g subfont

Recommended usage

Run subfont on the files you are ready to deploy to a static file hosting service. If these are build artifacts from another build system, and not the original files, run subfont path/to/artifacts/index.html -i to have subfont clobber the dist files in their original location.

If you want to run directly against your raw original files, it is recommended to create a recursive copy of your files which you run subfont on. This keeps your original authoring abstraction unchanged.

Including additional characters in the subsets

If you have a use case where the automatic tracing doesn't find all the characters you need, you can tell subfont to include specific characters in the subsets by adding a custom -subfont-text property to the respective @font-face declarations.

Example where all numerical digits are added to the bold italic Roboto variant:

@font-face {
  font-family: Roboto;
  font-style: italic;
  font-weight: 700;
  src: url(roboto.woff) format('woff');
  -subfont-text: '0123456789';
}

An easier, but less fine-grained option is to use the --text switch to include a set of characters in all created subsets.

Other usages

You can have subfont output a copy of your input files to a new directory. This uses Assetgraph to trace a dependency graph of your website and writes it to your specified output directory. Be aware of any errors or warnings that might indicate Assetgraph having problems with your code, and be sure to double check that the expected files are in the output directory. Run subfont path/to/index.html -o path/to/outputDir.

You can also have subfont scrape a website directly using http and write the output to local disk. This use is likely to fail in a number of ways and should mostly considered a demo feature if you just want to give the tool a quick go to see what it will do to your page. Run subfont https://yourpage.me -o path/to/outputDir.

Command line options

$ subfont --help
Create optimal font subsets from your actual font usage.
subfont [options] <htmlFile(s) | url(s)>

Options:
  --help                             Show help                                           [boolean]
  --version                          Show version number                                 [boolean]
  --root                             Path to your web root (will be deduced from your input files
                                     if not specified)                                    [string]
  --canonical-root, --canonicalroot  URI root where the site will be deployed. Must be either an
                                     absolute, a protocol-relative, or a root-relative url[string]
  --output, -o                       Directory where results should be written to         [string]
  --browsers                         Override your projects browserslist configuration to specify
                                     which browsers to support. Controls font formats and
                                     polyfill. Defaults to browserslist's default query if your
                                     project has no browserslist configuration            [string]
  --formats                          Font formats to use when subsetting. The default is to select
                                     the formats based on the browser capabilities as specified
                                     via --browsers or the browserslist configuration.
                                                    [array] [choices: "woff2", "woff", "truetype"]
  --text                             Additional characters to include in the subset for every
                                     @font-face found on the page                         [string]
  --fallbacks                        Include fallbacks so the original font will be loaded when
                                     dynamic content gets injected at runtime. Disable with
                                     --no-fallbacks                      [boolean] [default: true]
  --dynamic                          Also trace the usage of fonts in a headless browser with
                                     JavaScript enabled                 [boolean] [default: false]
  --in-place, -i                     Modify HTML-files in-place. Only use on build artifacts
                                                                        [boolean] [default: false]
  --inline-css                       Inline CSS that declares the @font-face for the subset fonts
                                                                        [boolean] [default: false]
  --font-display                     Injects a font-display value into the @font-face CSS.
             [string] [choices: "auto", "block", "swap", "fallback", "optional"] [default: "swap"]
  --recursive, -r                    Crawl all HTML-pages linked with relative and root relative
                                     links. This stays inside your domain
                                                                        [boolean] [default: false]
  --relative-urls                    Issue relative urls instead of root-relative ones
                                                                        [boolean] [default: false]
  --silent, -s                       Do not write anything to stdout    [boolean] [default: false]
  --debug, -d                        Verbose insights into font glyph detection
                                                                        [boolean] [default: false]
  --dry-run, --dry, --dryrun         Don't write anything to disk       [boolean] [default: false]

Other great font tools

https://meowni.ca/font-style-matcher/

License

MIT

More Repositories

1

fusile

A web asset precompiling file system proxy.
HTML
233
star
2

hyperlink

A node library and command line tool to test the integrity of your internal an external hyperlinks
JavaScript
227
star
3

grunt-reduce

A grunt kitchen that reduces your web ingredients down to their essence for optimal serving. Bon appétit!
JavaScript
184
star
4

assetviz

Assetviz is a web application code base visualization tool. Generate a self encapsulated html-file with a force directed graph representing the assets in your project and their relations.
JavaScript
87
star
5

netlify-plugin-checklinks

Netlify build plugin check your links and asset references
JavaScript
86
star
6

netlify-plugin-subfont

Netlify build plugin to run automated web font loading optimizations on static pages
JavaScript
67
star
7

node-histogram

Javascript histogram library that gives you a data structure describing your PNG/JPEG/GIF. Works in NodeJS and any canvas supporting browser. Added bonus: Exports AMD module in the browser if require.js is loaded, otherwise falls back to exposing histogram on window.
JavaScript
62
star
8

generator-greenfield

A full and clean frontend web workflow Yeoman generator. Simple configuration, powerful preprocessing and image pipeline, livereload and a highly optimized production build output
ApacheConf
42
star
9

netlify-plugin-hashfiles

Netlify build plugin to get optimal file caching with hashed file names and immutable cache headers
JavaScript
32
star
10

express-systemjs-translate

Express middleware to speed up systemjs development loads by running translations serverside
JavaScript
28
star
11

tolk

A file reader that promises to translate non-web assets to web assets given the available transpilers. Autoprefixing, sourcemaps and all!
HTML
27
star
12

generator-npm-webapp

A full and clean frontend web workflow Yeoman generator with npm as task runner. Simple configuration, powerful preprocessing and image pipeline, livereload and a highly optimized production build output
JavaScript
16
star
13

express-compile-sass

Express middleware to compile sass in the HTTP stream
CSS
15
star
14

yify-query

Find torrent magnet links from the yify database directly from the command line or in your node modules
JavaScript
14
star
15

todomvc-challenge

Challenge: Use assetgraph to build every example app from TasteJS/TodoMVC
JavaScript
13
star
16

contentsecure

A Content Security Policy auto generator (DEPRECATED)
JavaScript
12
star
17

expush

Express with spdy push of static assets and proxy passthrough for non-static assets
JavaScript
11
star
18

pipetteur

A function to extract any colors from a string
JavaScript
11
star
19

grunt-livestyle

A static file development server with automated file watching, less/sass/jsx preprocessing, image preprocessing, autoprefixing and proxy passthrough
JavaScript
10
star
20

episode

JavaScript utility function to find tv series season and episode numbers from a string
JavaScript
9
star
21

synesthesia

A collection of regular expressions to match color syntax substrings from a text
JavaScript
7
star
22

svg-clock

JavaScript
7
star
23

dotfiles

Shell
7
star
24

webapp-skel

Web application skeleton directory set up for builds of webapps with Ext JS using assetgraph-builder
JavaScript
6
star
25

bower-to-jspm

Utility to help you migrate from bower to jspm. Finds packages on npm and github and generates jspm install command lines
JavaScript
6
star
26

express-legacy-csp

Downgrade content-security-policy version and fidelity to support the requesting browser
JavaScript
6
star
27

jspm-config-test

A tool to run through your jspm config and check if all modules load without errors. Helps debug missing dependencies or shims
JavaScript
5
star
28

schemes

IANA Uniform Resource Identifier (URI) Schemes list, including crowd sourced unofficial ones
JavaScript
5
star
29

webpack-assetgraph-plugin

EXPERIMENTAL! Assetgraph plugin for webpack that will include all referenced external assets in the build
JavaScript
5
star
30

buildfu

A collection of CLI tools for improving web performance optimization and building webapps
JavaScript
5
star
31

generator-webapp-assetgraph

An alternative grunt workflow leveraging the power of Assetgraph
ApacheConf
5
star
32

ambitus

A calendar interval controller
JavaScript
5
star
33

ezflix

Play video directly from eztv torrents
JavaScript
4
star
34

playify

Play movies from yify directly from the command line using torrentstream
JavaScript
4
star
35

pressable

JavaScript representations of pressable keys that aren't text. These are stored in the Unicode PUA (Private Use Area) code points, 0xE000-0xF8FF.
JavaScript
4
star
36

JS-snippets

Collection of often used JS scripts
JavaScript
4
star
37

fontinspect

Trace the web font usage of a particular web page on the command line
JavaScript
4
star
38

requirejs-istanbul

RequireJS plugin to instrument modules with Istanbul for code coverage
JavaScript
3
star
39

www.browserling.com

Build system experiment using www.browserling.com as an example
JavaScript
3
star
40

LSB-improvement

Lån og Spar netbank forbedring via Chrome/Firefox userscript
JavaScript
2
star
41

coronasmitte.netlify.app

A clone of the Danish Police website limited to the sections about coronavirus.
JavaScript
2
star
42

no-build-system

A talk about build systems for EmpireJS 2014
CSS
2
star
43

mntr.dk

My blog
CSS
2
star
44

plugin-subfont-demo

Demo page for Jamstack 2020 virtual netlify-plugin-subfont
HTML
2
star
45

colorcat

Demo: CSS3 nyan cat with color adjustment inputs using One-color.js
JavaScript
2
star
46

micro.offset

Microlib to get the offset of a DOM element on the page
JavaScript
2
star
47

RevyTeX

LaTeX environment and scripts for the science revues at Copenhagen university
TeX
2
star
48

BallsBallsBalls

A quiz about balls
CSS
2
star
49

hoodie-css-local

Example setup for applying local css to remote proxied website
HTML
2
star
50

node-color-commando

Nothing but the bare naked color math. CLI owns a pretty color picker every time!
JavaScript
2
star
51

assetgraph-webbundle

Assetgraph transform to create a webbundle from the existing graph
JavaScript
2
star
52

tap-spot

Compact dot reporter for TAP output. Supports skip and todo
JavaScript
2
star
53

talk-images

Assets for a talk about auto generated image variants in development and static builds
CSS
2
star
54

svelte-a11y-tree

Svelte-based implementation of the WAI-ARIA TreeView: https://www.w3.org/TR/wai-aria-practices/#TreeView
JavaScript
2
star
55

toggleprint

Defines a hotkey that can toggle your print stylesheets to be applied on your screen for fast print stylesheet iteration
JavaScript
2
star
56

rollcount

An experiment in CSS 3d transforms for making a rolling slot counter
CSS
1
star
57

coin

Mac Donalds coin offer code generator
JavaScript
1
star
58

hyperlink-webpack

Temporary testing ground for running hyperlink on webpack docs
HTML
1
star
59

requirejs-react-hotload

JavaScript
1
star
60

assetgraph-relation-htmlimportmap

Assetgraph relation to model import maps from HTML assets
JavaScript
1
star
61

talk-transpiling-recomposed

A talk about the complexity of configuring transpilers for your web development workflows
JavaScript
1
star
62

system-plugin-jsx-bug

JavaScript
1
star
63

ren-lyrics

Lyrics and subtitles of Ren songs with translations
1
star
64

perf

JavaScript
1
star
65

jquery-datatables

HTML
1
star
66

jquery-prestige

A jQuery plugin that makes any dom element a clickable file input.
CSS
1
star
67

micro.mouse

Microlib to fix mouse event differences
JavaScript
1
star
68

companydata

JavaScript
1
star
69

node-untile

Combines map tiles into a sinlge map png
JavaScript
1
star
70

semihkirdinli.github.io

HTML
1
star
71

node-sass-evergreen

node-sass compatibility wrapper providing nodes-sass compatibility with previous major versions
JavaScript
1
star
72

yeoman-angular-reduce-example

Example repos to demonstrate how to adapt a yeoman generated angular application to use grunt-reduce as a build system
JavaScript
1
star
73

m.lanyrd.com

Repo for experimenting with build system optimization of m.lanyrd.com
Shell
1
star
74

Userscripts

Random userscripts for different websites I use
JavaScript
1
star
75

apollo-pokedex-experiment

Personal playground for learning Apollo and Graphql via Pokedex
JavaScript
1
star
76

MochaJsdomReact

Temporary repository to debug a crazy Mocha / Jsdom / React combination failure
JavaScript
1
star
77

seespee.netlify.com

Website for seespee
JavaScript
1
star
78

CloudPun

Pun web page for cloud presentation at Open Source Days
JavaScript
1
star
79

FileJS

A collection of small decoupled javascript AMD modules for file input and upload
JavaScript
1
star