0.1.2 • Published 5 years ago

prefetch-svg v0.1.2

Weekly downloads
3
License
ISC
Repository
github
Last release
5 years ago

prefetch-svg

prefetch-svg is a library to prefetch @import() and url() in the CSS of the SVG. Replacing import() with its content and url() with a data url.

Motivation

SVG can contain CSS that contains @import() and url(), this leads to bad looking offline SVG. The idea is to prefetch all URLs and assemble them inside the SVG itself. This increase the SVG size but make it usable offline and in <img> tags.

Examples

example

Live examples:

Install

npm install --save prefetch-svg

Or if you want to use the CLI

npm install -g prefetch-svg

Usage

Node

const prefetchSvg = require('prefetch-svg');
prefetchSvg('<svg>...</svg>').then(prefetchedSvg => { ... });

Browser

You can use a CDN to use this package. (see example)

<script src="https://unpkg.com/prefetch-svg/dist/prefetchSvg.umd.js"></script>
<script>
prefetchSvg('<svg>...</svg>').then(prefetchedSvg => { ... });
</script>

Or you can use module bundler. (see example)

import prefetchSvg from "prefetch-svg/dist/prefetchSvg.esm.js";
prefetchSvg('<svg>...</svg>').then(prefetchedSvg => { ... });

CLI

This package also provide a CLI.

Usage: prefetch-svg <input> <output>

Author

Jason Yu (me@ycmjason.com)

0.1.2

5 years ago

0.1.1

6 years ago

0.1.0

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago