Figure out a good story about image bundling
Opened this issue · 6 comments
The upstream registry has image URLs that point at Github. While this is fine for now we eventually want to avoid network traffic.
To do this, Prax will want to bundle the asset images into the extension and serve them to pages. It will probably need to rewrite image URLs to do this. Perhaps this should be done by the registry compiler.
Actually, was just working on a spike of this yesterday: https://github.com/prax-wallet/registry/blob/inline-santiize/src/sanitize.rs
The idea was to 1) fetch the png/svg, 2) sanitize the svg for bad scripts, and 3) convert to base64 data blobs that can directly be used in an <img>
tag.
One drawback is that this increases the size of our registry (possibly significantly) given image data is now baked in. Options:
- Be ok with a larger registry.json
- Render two versions of the generated registry (one with images embedded and one with links)
I'd like to avoid bundling base64 encoded data in the Metadata.
Chrome extensions can serve files, so I'd prefer that the extension rewrites the image paths to come from the extension and then the frontend content can use them in a src tag.
The mechanism I was thinking of is web_accessible_resources. I think we should aim to have the prax registry compile asset images into some format that we (or someone else) can easily move into that structure
Ah ok, I thought your suggestion for the registry compiler was an indication it should happen in Rust land. L had suggested similar ideas about using web_accessible_resources.
However, if the extension at build time needs to download the registry json, it's also easy in that same step to convert all of the URLs to data blobs (data:image/png;base64...). It then can be used in the src tag all the same without needing to do file hosting. This would essentially make the metadata saved in indexeddb also be hosting the image files. Thoughts on that approach?
Actually, hmm. That may not be as desirable to have potentially weighty img data attached to the metadata. Also, we should investigate if web_accessible_resources allows for wildcards and doesn't need to be enumerated files.
Another note is that there are contexts in which the extension is not available (insights dashboard, dex explorer), and we still want to be able to display images here.