# 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.

Latest version **0.1.2** (published 2018-11-23) · ISC license · 0 weekly downloads

## Install

```sh
npm install prefetch-svg
pnpm add prefetch-svg
yarn add prefetch-svg
bun add prefetch-svg
```

Provides the command `prefetch-svg`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.2 |
| Published | 2018-11-23 |
| First published | 2018-07-02 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 126.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Jason Yu |
| Maintainers | ycm.jason |
| Keywords | svg, prefetch, offline |

## Links

- npm: https://www.npmjs.com/package/prefetch-svg
- Repository: https://github.com/ycmjason/svg-offline
- Homepage: https://github.com/ycmjason/svg-offline#readme
- Issues: https://github.com/ycmjason/svg-offline/issues
- npm.io page: https://npm.io/package/prefetch-svg

## Dependencies (1)

- [node-fetch](https://npm.io/package/node-fetch.md) ^2.3.0

## Recent versions

- 0.1.2 (latest) — 2018-11-23
- 0.1.1 — 2018-07-02
- 0.1.0 — 2018-07-02
- 0.0.3 — 2018-07-02
- 0.0.2 — 2018-07-02

## README

# 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](examples/example1.png)

Live examples:
- Node.js (WIP)
- [CDN](https://repl.it/@ycmjason/prefetch-svg-cdn)
- [Module bundler](https://codesandbox.io/s/qv198lvqpq)

## Install

```
npm install --save prefetch-svg
```

Or if you want to use the CLI

```
npm install -g prefetch-svg
```

## Usage

### Node

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

### Browser

You can use a CDN to use this package. (see [example](https://repl.it/@ycmjason/prefetch-svg-cdn))

```html
<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](https://codesandbox.io/s/qv198lvqpq))

```js
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)

---
_Source: https://npm.io/package/prefetch-svg · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
