Decrease embedded img size for inlineImages#836
Conversation
|
Alternatively, there's also WEBP. According to https://developers.google.com/speed/webp/docs/webp_lossless_alpha_study it supports transparency and should be smaller. For reference, I tried the same page, with |
|
Thank you for pinging me! I think the work is great. About the compression switch, compression ratio, and final format, personally, I suggest making them configurable. How do you think about it @Yuyz0112 |
|
Same here, extending inline images config to an object may help. |
|
Guys, how about creating an optional param object Then if you provide something like What do you guys thing? |
|
Good point! I think it could work. If changing canvas recording, I think @Juice10 may take a look as well. |
|
Nice idea +1. The only concern is the API design since we need to keep compatibility. |
|
So I checked a few pages in both Firefox and Chrome and it seems that providing nullable params to Eg: I implemented |
I can't think of any reason to use separate image types for canvas, versus img.
Unifying the config for canvas and images makes sense to me |
|
If you'd like to decrease the embedded img size for inline images, why not try to use the existing image? Using fetch comes with the benefit that we won't have to use Big downside to both |
|
I have actually tried the image fetch option, when I started working on the offline image feature. It's a bit of work to make all the functions in the snapshot.ts file async, but it makes it easier to wait for some callbacks and events. |
I totally agree that this PR is the next logical step to what we already have, and makes sense to do any image fetching or async work in a separate PR. Especially if we want to make the snapshot async. What we could potentially do to keep everything sync, is to create a new type of event that contains the url of the image, and the contents. And then in the replayer we can loop through all of these new types of events to know what urls have been saved, and when the replayer creates an image it can check to see if we have an offline copy of that url and replace the contents of it with the saved version. rrweb/packages/rrweb/src/replay/index.ts Line 125 in f74b7bb Credits go to @Yuyz0112 for coming up with this concept |
Hi.
This is a small PR for decreasing the final snapshot size, for the majority of pages.
For example a page with lots of images like: https://www.1samsautos.com/2005-GMC-Safari-Passenger-Denver-CO-Fort-Collins-Colorado-Springs-Kansas-City-DENVER/used_car/Wrqim%5bzGkRg%3d ; currently the snapshot size jumps between 96MB and 120MB, depending on how much I'm waiting for the page to load, or if I'm scrolling, because the images are loaded lazily on scroll event.
If we merge this PR, the snapshot size will be only 12MB, so 10x smaller.
However there may be some issues with this hard-coded convert-all-to-JPEG approach:
canvas.toDataURL()function would return a smaller string if we used PNG? there are large, mostly monochrome images that can be smaller as PNG.There doesn't seem to be a built-in way to check the HTMLImageElement Content-type, or MIME-type. If the image was GIF or PNG we could just convert it to PNG, otherwise would be JPEG. We could use the img src extension, but that's not reliable.
Ping @Mark-Fenng again, because you know this feature very well already. I hope you don't mind 😄