kibana/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
..
content_management_examples [SharedUX] Replace KibanaRenderContextProvider usage (#220170) 2025-06-12 08:39:59 -07:00
controls_example Optimize existing image assets with lossless compression (#223998) 2025-06-19 16:44:13 +02:00
data_view_field_editor_example Upgrade EUI to v101.0.1 (#215698) 2025-03-28 19:29:23 +01:00
developer_examples Optimize existing image assets with lossless compression (#223998) 2025-06-19 16:44:13 +02:00
discover_customization_examples Optimize existing image assets with lossless compression (#223998) 2025-06-19 16:44:13 +02:00
embeddable_examples Fix: success message and scroll after adding panel from library (#220122) 2025-05-09 13:24:49 -04:00
error_boundary Upgrade EUI to v101.0.1 (#215698) 2025-03-28 19:29:23 +01:00
eso_model_version_example APEX-54 Stricter type checking for unsafe_transform functions (#222973) 2025-06-13 12:29:13 +02:00
esql_ast_inspector Optimize existing image assets with lossless compression (#223998) 2025-06-19 16:44:13 +02:00
esql_validation_example Optimize existing image assets with lossless compression (#223998) 2025-06-19 16:44:13 +02:00
expressions_explorer SKA: Update broken references and URLs (#206836) 2025-01-28 03:32:48 +00:00
feature_control_examples [Authz] Mandatory Security Config (#215180) 2025-03-27 12:04:53 -07:00
feature_flags_example [Authz] Mandatory Security Config (#215180) 2025-03-27 12:04:53 -07:00
field_formats_example Optimize existing image assets with lossless compression (#223998) 2025-06-19 16:44:13 +02:00
files_example Upgrade EUI to v101.0.1 (#215698) 2025-03-28 19:29:23 +01:00
grid_example [kbn-grid-layout] Flatten grid layout (#218900) 2025-05-21 08:01:13 -06:00
guided_onboarding_example [SharedUX] Replace KibanaRenderContextProvider usage (#220170) 2025-06-12 08:39:59 -07:00
hello_world Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
locator_examples Adds AGPL 3.0 license (#192025) 2024-09-06 19:02:41 -06:00
locator_explorer SKA: Update broken references and URLs (#206836) 2025-01-28 03:32:48 +00:00
partial_results_example Upgrade EUI to v101.0.1 (#215698) 2025-03-28 19:29:23 +01:00
portable_dashboards_example Optimize existing image assets with lossless compression (#223998) 2025-06-19 16:44:13 +02:00
preboot_example [Authz] Mandatory Security Config (#215180) 2025-03-27 12:04:53 -07:00
resizable_layout_examples Optimize existing image assets with lossless compression (#223998) 2025-06-19 16:44:13 +02:00
response_stream [Charts] Use chartTheme hook everywhere (#217370) 2025-04-14 18:09:15 +02:00
routing_example [Authz] Mandatory Security Config (#215180) 2025-03-27 12:04:53 -07:00
screenshot_mode_example Change reporting CODEOWNERS to response ops (#213560) 2025-04-04 23:27:42 +02:00
search_examples Optimize existing image assets with lossless compression (#223998) 2025-06-19 16:44:13 +02:00
share_examples [Reporting] fix dashboard "Copy Post URL" action (#192530) 2024-10-08 01:54:21 +02:00
sse_example [Authz] Mandatory Security Config (#215180) 2025-03-27 12:04:53 -07:00
state_containers_examples Optimize existing image assets with lossless compression (#223998) 2025-06-19 16:44:13 +02:00
ui_action_examples [SharedUX] Replace KibanaRenderContextProvider usage (#220170) 2025-06-12 08:39:59 -07:00
ui_actions_explorer Optimize existing image assets with lossless compression (#223998) 2025-06-19 16:44:13 +02:00
unified_doc_viewer Upgrade ES client to 9.0.0-alpha.3 (#208776) 2025-02-25 14:37:23 +00:00
unified_field_list_examples Optimize existing image assets with lossless compression (#223998) 2025-06-19 16:44:13 +02:00
unified_tabs_examples Optimize existing image assets with lossless compression (#223998) 2025-06-19 16:44:13 +02:00
user_profile_examples Upgrade EUI to v102.3.0 (#222149) 2025-06-09 11:04:46 +02:00
v8_profiler_examples [Authz] Mandatory Security Config (#215180) 2025-03-27 12:04:53 -07:00
README.asciidoc Adds run without basepath configured to examples readme (#173086) 2023-12-12 11:22:02 -07:00

[[example-plugins]]
== Example plugins

This folder contains example plugins.  To run the plugins in this folder, use the `--run-examples` flag (without a basepath), via

[source,bash]
----
yarn start --run-examples
----