css-font-local-cache

encode fonts directly into css text for offline use

Usage no npm install needed!

<script type="module">
  import cssFontLocalCache from 'https://cdn.skypack.dev/css-font-local-cache';
</script>

README

css-font-local-cache

github actions test npm downloads npm version

Allow using fonts linked in your CSS offline by enconding them in base64 into the CSS itself. I use this for offline-first Electron apps, but you can use it for whatever you want.

Install

npm install css-font-loca-cache

API

const { promises: fs } = require('fs');
const cssFontCache = require('css-font-local-cache');

(async () => {
  const input = await fs.readFile('./css-with-links.css', 'utf8');
  const output = await cssFontCache(input);
  await fs.writeFile('./css-with-base64-fonts.css', output);
})();

CLI

Encode CSS you already have on disk:

npx css-font-local-cache < css-with-links.css > css-with-base64-fonts.css

Encode CSS from a remote location:

npx css-font-loca-cache http://example.com/my-css > css-with-base64-fontd.css