modern-fontmin
v0.0.1
Published
Fastest cropping font files in the browser
Downloads
14
Maintainers
Readme
Install
npm i modern-fontmin
# peerDependencies
npm i pako
Usage
import { minify, arrayBufferToDataUrl } from 'modern-fontmin'
window.fetch('./font.woff')
.then(rep => rep.arrayBuffer())
.then(font => {
const min = minify(font, 'You want a subset of the text')
console.log('raw size', font.byteLength / 1024, 'kb')
console.log('min size', min.byteLength / 1024, 'kb')
const dataUrl = arrayBufferToDataUrl(min, 'font/woff')
const style = document.createElement('style')
style.appendChild(
document.createTextNode(`
@font-face {
font-family: "CustomFont";
src: url(${ dataUrl }) format("woff");
}
`),
)
document.head.append(style)
})