Optimise Grafana app plugin bundle size using React.lazy, Suspense, and webpack code splitting. Use when the user asks to reduce plugin bundle size, optimise module.js, add code splitting, improve initial plugin load…
---
name: plugin-bundle-size
license: Apache-2.0
description:
Optimise Grafana app plugin bundle size using React.lazy, Suspense, and webpack code splitting.
Use when the user asks to reduce plugin bundle size, optimise module.js, add code splitting,
improve initial plugin load performance, split plugin chunks, lazy load plugin pages, or
help implement lazy loading in a Grafana app plugin. Triggers on phrases like "optimise plugin
bundle size", "module.js is too large", "plugin is slow to load", "code split the plugin",
"reduce initial JS payload", or "help me with Suspense in my plugin".
---
# Grafana plugin bundle size optimisation
`module.js` is the render-blocking entry point for every Grafana app plugin. The smaller it is, the less impact the plugin has on Grafana's overall startup time. A well-split plugin should have a `module.js` under ~200 KB that contains nothing but lazy-loaded wrappers — all feature code loads on demand.
**Target:** ~15–25 JS chunks total. Fewer means too little splitting; far more (50+) means over-engineering.
## Risk levels
Not all splitting opportunities carry the same risk. Apply them in this order:
| Level | What | Risk | Impact |
|---|---|---|---|
| **Safe** | `module.tsx` lazy wrappers (Priority 1) | Very low — no behaviour change | Highest — module.js drops 90%+ |