SVGs in our products feature all kinds of markup, in parts with editor specific metadata, resulting in unnecessary inconsistency and bloat.
We're using SVGO for optimization and go for manual QA, both on code and visual level.
Optimizations achieved are between 3%–27% file size on average before gzipping, in a few cases, like MMV even up to 78%.
Among changes:
- Unify XML declaration, preferable (altough maybe slighly esoteric) with uppercase UTF-8: <?xml version="1.0" encoding="UTF-8"?>
- Removing standalone="no" attribute as its default
- Removing additional DOCTYPE
- Setting of width and height attributes together with viewport for widest cross-browser compatibility, example: <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 20 20">
- Removing px value unit as it's default
- Removing non-standard enable-background attribute, removed from SVG standard altogether
- Reduction of ids where applicable
- Changing indentation to use tabs & reduce whitespace where applicable, example: "/> not " />
- Minify and lowercase colors, example: #fff not #FFFFFF
- Collapsing useless groups g
- Merging paths where applicable
- Removing editor (InkScape, Illustrator etc.) data
- Removing unnecessary style attributes where applicable
- Removing unused defs
- Removing raster images where applicable
- Sorting attributes
Above optimizations are a mix of SVGO's available plugins and manual optimizations. They've been collected now at https://www.mediawiki.org/wiki/Manual:Coding_conventions/SVG
Products optimized:
- MediaWiki core – https://gerrit.wikimedia.org/r/#/c/386254/
Themes:
- Vector – https://gerrit.wikimedia.org/r/#/c/386134/ & https://gerrit.wikimedia.org/r/#/c/575812/
- MinervaNeue – https://gerrit.wikimedia.org/r/#/c/389290/
Extensions:
- CentralNotice – https://gerrit.wikimedia.org/r/387494
- Cite – https://gerrit.wikimedia.org/r/388161
- Echo – https://gerrit.wikimedia.org/r/#/c/389230/
- StructuredDiscussions (Flow) – https://gerrit.wikimedia.org/r/#/c/390557/
- GettingStarted – https://gerrit.wikimedia.org/r/#/c/384334/
- GuidedTour – https://gerrit.wikimedia.org/r/383415
- Kartographer – https://gerrit.wikimedia.org/r/#/c/387164/
- MobileFrontend – https://gerrit.wikimedia.org/r/#/c/373898/ Savings between 5 and 21% in file size
- MultimediaViewer – https://gerrit.wikimedia.org/r/388833 – example prev.svg: Before: compression ratio: 232 %, original size: 2080 bytes, gzipped result size: 898 bytes. After: compression ratio: 204 %, original size: 1080 bytes, result size: 530 bytes
- OOUI – https://gerrit.wikimedia.org/r/387372 Savings between 3 and 27% in file size
- PagePreviews (Popups) – https://gerrit.wikimedia.org/r/#/c/384432/
- RelatedArticles – https://gerrit.wikimedia.org/r/#/c/399133/
- Translate – https://gerrit.wikimedia.org/r/#/c/380062/
- TwoColConflictEdit – https://gerrit.wikimedia.org/r/#/c/399136/
- UniversalLanguageSelector – https://gerrit.wikimedia.org/r/#/c/387992/
- VisualEditor – https://gerrit.wikimedia.org/r/#/c/388933/
Projects:
- Portal – https://gerrit.wikimedia.org/r/#/c/377881/ & extended with more images https://gerrit.wikimedia.org/r/387192
- Style Guide – https://github.com/wikimedia/WikimediaUI-Style-Guide/pull/54
Sign off steps
- Make sure all subtasks are resolved.