Gathering detailed insights and metrics for @netless/mini-svg-data-uri
Gathering detailed insights and metrics for @netless/mini-svg-data-uri
Gathering detailed insights and metrics for @netless/mini-svg-data-uri
Gathering detailed insights and metrics for @netless/mini-svg-data-uri
Small, efficient encoding of SVG data URIs for CSS, HTML, etc.
npm install @netless/mini-svg-data-uri
Typescript
Module System
Node Version
NPM Version
JavaScript (97.93%)
TypeScript (2.07%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
324 Stars
33 Commits
15 Forks
5 Watchers
3 Branches
8 Contributors
Updated on Jul 10, 2025
Latest Version
0.0.1
Package Id
@netless/mini-svg-data-uri@0.0.1
Unpacked Size
10.29 kB
Size
4.86 kB
File Count
8
NPM Version
6.14.13
Node Version
14.17.0
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
No dependencies detected.
data:
URIThis tool converts SVGs into the most compact, compressible data:
URI that SVG-supporting browsers tolerate. The results look like this (169 bytes):
1data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 50 50' 2%3e%3cpath d='M22 38V51L32 32l19-19v12C44 26 43 10 38 0 52 15 49 39 22 38z'/%3e 3%3c/svg%3e
Compare to the Base64 version (210 bytes):
1data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIH 2ZpZXdCb3g9IjAgMCA1MCA1MCI+PHBhdGggZD0iTTIyIDM4VjUxTDMyIDMybDE5LTE5djEyQzQ0IDI2ID 3QzIDEwIDM4IDAgNTIgMTUgNDkgMzkgMjIgMzh6Ii8+PC9zdmc+
Or the URL-encoded version other tools produce (256 bytes):
1data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org% 22F2000%2Fsvg%22%20viewBox%3D%220%200%2050%2050%22%3E%3Cpath%20d%3D%22M22%2038V51 3L32%2032l19-19v12C44%2026%2043%2010%2038%200%2052%2015%2049%2039%2022%2038z%22%2 4F%3E%3C%2Fsvg%3E
For a more realistic example, I inlined the icons from the Open Iconic project into CSS files with the 3 above methods:
Compression | Base64 | Basic %-encoding | mini-svg-data-uri |
---|---|---|---|
None | 96.459 kB | 103.268 kB | 76.583 kB |
gzip -9 | 17.902 kB | 13.780 kB | 12.974 kB |
brotli -Z | 15.797 kB | 11.693 kB | 10.976 kB |
Roughly 6% smaller compressed, but don't write off the ≈20% uncompressed savings either. Some browser caches decompress before store, and parsing time/memory usage scale linearly with uncompressed filesize.
1var svgToMiniDataURI = require('mini-svg-data-uri'); 2 3var svg = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 50 50"><path d="M22 38V51L32 32l19-19v12C44 26 43 10 38 0 52 15 49 39 22 38z"/></svg>'; 4 5var optimizedSVGDataURI = svgToMiniDataURI(svg); 6// "data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 50 50'%3e%3cpath d='M22 38V51L32 32l19-19v12C44 26 43 10 38 0 52 15 49 39 22 38z'/%3e%3c/svg%3e"
You can also try it in your browser at RunKit.
If you have it installed globally, or as some kind of dependency inside your project’s directory:
1mini-svg-to-data-uri file.svg # writes to stdout 2mini-svg-to-data-uri file.svg file.svg.uri # writes to the given output filename
Use --help
for more info.
This does not optimize the SVG source file. You’ll want svgo or its brother SVGOMG for that.
The default output does not work inside srcset
attributes. Use the .toSrcset
method for that:
1var srcsetExample = html` 2<picture> 3 <source srcset="${svgToMiniDataURI.toSrcset(svg)}"> 4 <img src="${svgToMiniDataURI(svg)}"> 5</picture>`;
The resulting Data URI should be wrapped with double quotes: url("…")
, <img src="…">
, etc.
This might change or break SVGs that use "
in character data, like inside <text>
or aria-label
or something. Try curly quotes (“”
) or "
instead.
charset
in the MIME Type?charset
does nothing for Data URIs. The URI can only be the encoding of its parent file — it’s included in it!
It compresses slightly better. No, really. Using the same files from earlier:
Compression | Uppercase (%AF ) | Lowercase (%af ) |
---|---|---|
gzip -9 | 12.978 kB | 12.974 kB |
brotli -Z | 10.988 kB | 10.976 kB |
I did say slightly.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 7/20 approved changesets -- score normalized to 3
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More