kibana/x-pack/examples
Marta Bondyra 65bdf1ff8e
Optimize existing image assets with lossless compression (#223998)
## Summary

This PR applies **lossless compression** to all SVG and JPG/PNG assets
across Kibana using:

- [`svgo`](https://github.com/svg/svgo) — for optimizing SVGs  
- [`image-optimize`](https://www.npmjs.com/package/image-optimize) — for
JPG/PNG compression

‼️**Please scroll to ''Unknown metric groups" accordion to see what's
the gain for your code.**
<img width="542" alt="Screenshot 2025-06-18 at 13 24 20"
src="https://github.com/user-attachments/assets/191afb28-44fc-4551-9026-756a8385c66a"
/>

The goal is to reduce asset size and improve load performance without
compromising visual quality.

This PR achieves a **23 MB** reduction in asset size across all images
bundled in Kibana’s running code—meaning these compressed images
directly impact what ships in Kibana.
Some assets get bundled into chunks due to our bundling strategy but
might not actually be requested at runtime.

Additionally, I ran the same optimization script on the docs assets as a
harmless extra step, but those savings aren’t included in the 23 MB
total.

---

## Why

While working on Emotion rewrites, I noticed some SVGs seemed
unnecessarily heavy. That led to a broader investigation into our image
assets, and it turns out we’re not consistently optimizing them during
development or build.


---

## Notes

- Visual fidelity of optimized assets has been manually verified — no
visible differences
- The optimization is **lossless**, meaning no quality degradation
- Some assets (like large background images) could benefit further from
**lossy compression**

---

## Follow-ups / Ideas

1. **Automate compression in the dev/build pipeline**
   - e.g. add `svgo` as a pre-commit or CI step for SVGs
2. **Improve CI reporting**  
- Currently, bundle size diffs for images are hidden under "Unknown
metric groups" in the GitHub CI comment. We may want to make these more
visible.
   - 
3. **Audit large assets manually** — apply lossy compression where
appropriate
4. **Avoid redundant image loading**  
- e.g. background images on the login page are loaded again on the space
selector page since they’re bundled twice. I’m working on a separate PR
to address that.

## Snippets I used to apply the compression

```
# Find SVG files
find . -type f -iname "*.svg" \
  -not -path "*/node_modules/*" \
  -not -path "*/functional/*" > svg-files.txt

# Compress SVGs
while IFS= read -r file; do
  svgo "$file"
done < svg-files.txt
```

This snippet has been used for png and jpg, but the example below is for
png:
```
# Find PNG files
find . -type f -iname "*.png \
  -not -path "*/node_modules/*" \
  -not -path "*/functional/*" > png-files.txt

# Compress PNGs
while IFS= read -r file; do
  image-optimize -f jpg "$file"
done < png-files.txt
```
2025-06-19 16:44:13 +02:00
..
alerting_example [ResponseOps][Rules] Add solution field to rule types (#212079) 2025-03-12 17:19:58 +01:00
embedded_lens_example [embeddable] replace Embeddable ViewMode with presentation-publishing ViewMode (#211960) 2025-03-04 09:05:23 -07:00
exploratory_view_example Address some of the no_group_crossing dependencies (#198261) 2024-11-06 08:44:35 -06:00
gen_ai_streaming_response_example [ResponseOps] Check if we override EuiButton & EuiFilter styles (#222528) 2025-06-16 11:35:15 +03:00
lens_config_builder_example [embeddable] replace Embeddable ViewMode with presentation-publishing ViewMode (#211960) 2025-03-04 09:05:23 -07:00
lens_embeddable_inline_editing_example Optimize existing image assets with lossless compression (#223998) 2025-06-19 16:44:13 +02:00
screenshotting_example Change reporting CODEOWNERS to response ops (#213560) 2025-04-04 23:27:42 +02:00
testing_embedded_lens Optimize existing image assets with lossless compression (#223998) 2025-06-19 16:44:13 +02:00
third_party_lens_navigation_prompt Optimize existing image assets with lossless compression (#223998) 2025-06-19 16:44:13 +02:00
third_party_maps_source_example Optimize existing image assets with lossless compression (#223998) 2025-06-19 16:44:13 +02:00
third_party_vis_lens_example Optimize existing image assets with lossless compression (#223998) 2025-06-19 16:44:13 +02:00
triggers_actions_ui_example [Response Ops][Alerting] Alert Delete (#216613) 2025-06-09 13:49:54 +02:00
ui_actions_enhanced_examples [SharedUX] Replace KibanaRenderContextProvider usage (#220170) 2025-06-12 08:39:59 -07:00
README.md

Example plugins

This folder contains X-Pack example plugins. To run the plugins in this folder, use the --run-examples flag, via

yarn start --run-examples