Compress WebFonts using the font-spider CLI
masterTo compress WebFonts, you must first ensure your CSS @font-face rules reference an existing .ttf file. Font-spider will analyze your HTML and CSS files to identify used characters and then automatically generate compressed versions in woff2, woff, eot, and svg formats.
Step 1: Prepare your CSS
Ensure your @font-face declaration includes a path to a .ttf file:
@font-face {
font-family: 'source';
src: url('../font/source.eot');
src:
url('../font/source.eot?#font-spider') format('embedded-opentype'),
url('../font/source.woff2') format('woff2'),
url('../font/source.woff') format('woff'),
url('../font/source.ttf') format('truetype'),
url('../font/source.svg') format('svg');
font-weight: normal;
font-style: normal;
}
.home h1, .demo > .test {
font-family: 'source';
}Step 2: Run the CLI
Run the command followed by the HTML files you want to analyze:
font-spider [options] <htmlFile1 htmlFile2 ...>font-spider dest/news.html dest/index.html dest/about.html