Closed MattiasBuelens closed 5 years ago
Thank you for this! I've wanted this for some time. I'll check this out in a bit, and happy to have the SVG source back in the repo. I can imagine in the future, adding a rollup svg plugin for this as well. Are there any advantages of continuing using the SVG as an image source rather than inline at this point that you're aware of?
I can imagine in the future, adding a rollup svg plugin for this as well.
Unfortunately, rollup-plugin-svg
creates a base64 data URI... 😕 We could use rollup-plugin-string
instead to import the SVG file as a string (basically what rotate-instructions.js
now does manually).
Are there any advantages of continuing using the SVG as an image source rather than inline at this point that you're aware of?
Good point, hadn't even though of that. As far as I know, inline SVG works just fine. We can just .innerHTML = svgString
and we're done. 😛
Do you want me to try these things out in this PR?
@MattiasBuelens It's been working OK previously, so if this cuts down the size by 28k, that sounds great to me! Thank you for this improvement, I'll push this upstream to the webvr/webxr polyfills shortly
The base64-encoded SVG in
src/assets/rotate-instructions.js
takes up ~52 KB. The total bundle weighs in at 185 KB, so this single SVG accounts for 28% of the total bundle size. This is quite significant, and can be made much smaller with just a few easy changes.Here's what I've done:
"
with single quotes'
. (This avoids having to escape quotes when pasting in a double-quoted JS string literal.)To create a valid data URI, I replaced
Util.base64
with aUtil.dataUri
helper function. This function creates a data URI for a non-base64-encoded payload. Instead, it simply escapes any URL-unsafe characters in the payload. For more about this technique, see these blog posts by Chris Coyier and Taylor Hunt.As a result, the SVG weighs in at only ~24 KB, and the total bundle size drops to 157 KB. That's 28 KB less to download. 😄