fontoptim
Generates CSS with WOFF(2) fonts embedded as Base64. Use these CSS to load webfonts asynchronously, avoid invisible text and reduce flickering.
Based on ideas from Adam Beres-Deak’s article Better webfont loading with using localStorage and providing WOFF2 support.
Installation
npm install --save fontoptim
Example
You need WOFF and WOFF2 font files to use fontoptim (you can make them with Font Squirrel’s webfont generator):
var fs = ;var fontoptim = ;var fonts = 'PTSerif-Bold.woff': fs 'PTSerif-Bold.woff2': fs 'PTSerif-Italic.woff': fs // ...;var css = ;// css.woff = '@font-face{font-family:"PT Serif";src:url(data:application/font-woff;charset=utf-8;base64,d09GRgABAAAAAU...'// css.woff2 = '@font-face{font-family:"PT Serif";src:url(data:font/woff2;charset=utf-8;base64,d09GMgABAAAAA...'fs;fs;
Then load these CSS files with loadFont
function.
<!-- This script must be placed in the HEAD above all external stylesheet declarations (link[rel=stylesheet]) --> ...
See demo
folder for details.
Build systems
Grunt
Resources
- Better webfont loading with using localStorage and providing WOFF2 support
- Font Squirrel’s webfont generator
Changelog
The changelog can be found in the Changelog.md file.
Author
License
The MIT License, see the included License.md file.