-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SVG optimisation #79
Comments
Are there examples of bigger images whose optimisation is seriously sub-optimal? Until we find some cases where we can save at least 100kb I'm considering this pretty low priority. |
Given the reach this assets server now has across all our products and sites, I think we should prioritise any image optimisations we can. We're actually in a very fortunate position here in that we can make one change to this one codebase and significantly improve the performance of tens of sites almost instantly. In some cases, optimising might shave a negligible percentage from overall file sizes of an image asset but it other cases, such as complex pictograms, it could more than half the file size. Over the past couple of years, we have moved to using SVGs wherever possible but the assets server doesn't currently optimise them at all, serving them straight back to the client verbose with all metadata included; Actions
I'm hoping we can also run the above on all current images currently served as well as all new images? |
The asset server uses SVGO and imagemin but I believe there are improvements to be made to the settings. |
The clear problem with SVGs, which was highlighted during the performance workshop with @csswizardry, is that SVGs on the assets server aren't compressed. In fact, nothing is compressed at all, let alone compressed with Brotli. This will be fixed by moving the application to Kubernetes, which we hope to do at least by April 2020, but I've also filed an issue here to track it. I've looked into the benefits of compressing various SVGs that we use on our sites. I tested the following, hopefully representative, SVGs. When checking Gzip compression against Brotli, Brotli was better in every case, so I've only bothered showing Brotli compression in this test:
And I performed the following operations on each:
Important to note here that Cloudinary doesn't bother compressing formats that it thinks won't benefit from it - which includes PNG. So there's no point testing Brotli with Cloudinary images. Here are the resulting sizes, in bytes. The sizes here are so small we have to drop to bytes, rather than kilobytes, to see the differences (I reformatted the output a bit for readability):
Some observations:
Following the thread of the SVGs being very small in most cases, I was curious about the times involved in downloading them. Here are some examples from https://snapcraft.io/: These results kinda baffled me a bit - 2 files from cloudinary really took ages, but most of them took negligable "receive" (download) time compared to the "wait" time. The snapcraft logo took 11ms of "wait" then 20ms of "receive", whereas the 36ms it took to get Possible actions:
My thoughts To get optimal file-size on SVGs, we really need Brotli compression. Adding SVGO optimisation would also be a huge benefit. However, both of these are probably not the biggest optimisations we could make to performance overall simply because our SVGs do tend to be very small, and so most of the time spent getting the images is spent waiting for connections to open. Therefore the biggest win we could make would be to move the assets server to HTTP2, which should also be achieved by moving it to our Kubernetes infrastructure. Ideally, both of these would be irrellevant because we would request everything through Cloudinary which would automatically return the best file format with the optimal compression format. However, as this is currently not the case, we may want to consider optimising the assets server and then explicitly not using Cloudinary for SVGs. Although Cloudinary does support HTTP2 where the assets server does not. Until the assets server has HTTP2, we should use Cloudinary just for that reason, even without optimal filesize. I'm going to keep pushing on moving the assets server to k8s so that we can get Brotli + HTTP2, and so that we can actually do meaningful work on it. We may be able to move the assets server as soon as a couple of months' time, which will mean we can release optimisations and have Brotli compression, but we almost certainly won't have HTTP2 until after April 2020. |
I submitted a support ticket to Cloudinary with the following contents:
|
Excellent job on this @nottrobin 🙌🏻 |
For example,
The homepage of ubuntu.com has a image Google deems unoptimised.
Optimize the following images to reduce their size by 21.2KiB (97% reduction).
Compressing and resizing https://assets.ubuntu.com/v1/a0ae228b-laptop-base.png could save 21.2KiB (97% reduction).
The text was updated successfully, but these errors were encountered: