# svgxuse

> A polyfill that fetches external SVGs referenced in use elements when the browser itself fails to do so.

Latest version **1.2.6** (published 2017-10-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install svgxuse
pnpm add svgxuse
yarn add svgxuse
bun add svgxuse
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.6 |
| Published | 2017-10-25 |
| First published | 2016-01-06 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 736 |
| Author | Keyamoon |
| Maintainers | keyamoon |
| Keywords | svg, inline, svg, xlink:href, polyfill, external |

## Links

- npm: https://www.npmjs.com/package/svgxuse
- Repository: https://github.com/Keyamoon/svgxuse
- Homepage: https://github.com/Keyamoon/svgxuse#readme
- Issues: https://github.com/Keyamoon/svgxuse/issues
- npm.io page: https://npm.io/package/svgxuse

## Recent versions

- 1.2.6 (latest) — 2017-10-25
- 1.2.4 — 2017-04-05
- 1.2.3 — 2017-03-07
- 1.2.2 — 2017-02-28
- 1.2.1 — 2017-02-02
- 1.2.0 — 2017-02-02
- 1.1.23 — 2016-11-11
- 1.1.22 — 2016-09-28
- 1.1.21 — 2016-08-30
- 1.1.20 — 2016-08-03
- 1.1.19 — 2016-07-19
- 1.1.18 — 2016-07-04
- 1.1.17 — 2016-05-30
- 1.1.16 — 2016-03-31
- 1.1.15 — 2016-03-12
- … 11 more at https://npm.io/package/svgxuse/versions

## README

# svgxuse

A simple polyfill that fetches external SVGs referenced in `<use>` elements when the browser itself fails to do so.

Example of `<use>` with external reference:
```html
<svg class="icon icon-edit"><use xlink:href="symbol-defs.svg#icon-edit"></use></svg>
```

IE (9, 10, 11) fails to load **symbol-defs.svg** in the example above. svgxuse goes through every `<use>` element. If the element is referencing an external SVG and the browser has failed to load it, the script sends a GET request to grab and prepend the SVG to `<body>`.

[**Try this demo**](https://icomoon.io/svgxuse-demo/) in IE or other browsers to see how this polyfill works in action.

## Features

#### No browser sniffing
This polyfill relies on feature detection. As a result, it detects and attempts to solve issues in any browser that may fail to fetch the linked SVG. For example, cross domain linking to external SVGs may fail with this error:
`Unsafe attempt to load URL X from frame with URL Y. Domains, protocols and ports must match.`
Using svgxuse, your SVG would still load as long as it is served with proper CORS headers.
#### Doesn't try to support IE8
svgxuse is a polyfill and therefore doesn't need to support IE8. It's minimal and to the point.
#### No requestAnimationFrame or setTimeout for polling the DOM
Unlike similar solutions, svgxuse doesn't use requestAnimationFrame or setTimeout for polling the DOM.
#### No repetitive addition of inline SVGs
Instead of replacing `<use>` elements with SVG paths, svgxuse only adds symbol definitions to the markup once.

## Usage

```html
<script src="svgxuse.js" defer></script>
```
#### With NPM
```bash
npm install --save svgxuse
```
```html
<script defer src="node_modules/svgxuse/svgxuse.js"></script>
```
#### With Bower
```bash
bower install --save svgxuse
```
```html
<script defer src="bower_components/svgxuse/svgxuse.js"></script>
```

## License

MIT &copy; [IcoMoon.io](https://icomoon.io)

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