Performance optimization guide for Capacitor apps covering bundle size, rendering, memory, native bridge, and profiling. Use this skill when users need to optimize their app performance.
npx playbooks add skill cap-go/capacitor-skills --skill capacitor-performance
Find the bottleneck first (WebView JS, bridge, native, or network), then fix the specific cause. Generic web advice (code splitting, image compression, virtual lists) still applies; this skill focuses on what is different inside Capacitor.
TRIGGER when:
Do not use:
debugging-capacitor, capacitor-native-observability.ios-android-logs.capacitor-offline-first, sqlite-to-fast-sql.capacitor-splash-screen; keyboard resize jank -> capacitor-keyboard.capgo-live-updates.| Question | Tool |
|---|---|
| JS long tasks, layout, paint (iOS) | Safari > Develop > device > app > Timelines. Requires ios.webContentsDebuggingEnabled: true for release builds (debug builds are inspectable by default on iOS 16.4+). |
| JS long tasks, memory heap (Android) | chrome://inspect > Performance / Memory. |
| Native CPU, allocations, leaks (iOS) | Xcode > Product > Profile > Time Profiler / Allocations / Leaks; field data in Xcode Organizer > Metrics. |
| Native CPU/memory (Android) | Android Studio > Profiler. |
| Android cold start time | adb shell am force-stop <appId> && adb shell am start -W -n <appId>/.MainActivity (read TotalTime). |
| Android frame stats | adb shell dumpsys gfxinfo <appId> (janky frames %). |
| Android WebView version | adb shell dumpsys webviewupdate (current provider and version). |
Details and recipes: references/profiling.md.
@capacitor/camera 8.1+ API): use takePhoto / chooseFromGallery and display result.webPath; set targetWidth/targetHeight/quality. Avoid reading full-resolution base64 unless uploading. The older getPhoto / pickImages are deprecated.Capacitor.convertFileSrc(uri) for <img>/<video> src, Filesystem.readFileInChunks for large reads, @capacitor/file-transfer for uploads/downloads.WebView process terminated; Capacitor resets the bridge and reloads the page, so in-memory JS state is lost (looks like a restart). Android calls onRenderProcessGone; unless handled, the app is killed. Reduce peak memory (trap 1, large canvases, decoded images), persist critical state, restore on load.plugins.CapacitorHttp.enabled: true, fetch/XMLHttpRequest are routed through native and bodies cross the bridge. Great for CORS/cookies, slower for big downloads or streaming. Use file-transfer for big files.@capacitor/preferences (UserDefaults / SharedPreferences) is for small key/value data. Large JSON blobs are read/written whole and slow startup; use SQLite (for example @capgo/capacitor-fast-sql).loggingBehavior defaults to debug (logs only in debug builds). If it was set to production, every bridge call is logged in release; set it back to debug or none.server.url pointing to a LAN/live-reload server in a shipped build loads over network and fails offline. Remove before release; in Capacitor 9 use npx cap run <platform> --url for live reload instead of editing config.android.minWebViewVersion (default 60) only shows an error/server.errorPath; it does not update anything. Expensive CSS (backdrop-filter, large box-shadow/filter on scrolling content) janks on low-end WebViews.addListener returns Promise<PluginListenerHandle>; await it and call remove() on unmount. Re-registering on every route change multiplies native callbacks (appStateChange, keyboardWillShow, geolocation watchPosition - clear with clearWatch).launchAutoHide: false + SplashScreen.hide()), and defer non-critical plugin calls (analytics init, permission checks) until after first paint. Note Capacitor 9 changes Android launchFadeOutDuration default from 200 to 0.@capacitor/* packages creates lightweight proxies; their web implementations are already lazy-loaded via registerPlugin. Lazy-load heavy JS libraries (charts, PDF, maps SDK JS) and routes instead.TotalTime (Android) or Instruments App Launch / Organizer launch time (iOS), janky frame %, peak memory in Allocations/Profiler.grep -nE '"url"|loggingBehavior|webContentsDebuggingEnabled' capacitor.config.* and confirm no dev server.url.grep -rnE "resultType: *CameraResultType.Base64|readFile\(|getPhoto\(" src/.| Message / symptom | Meaning | Fix |
|---|---|---|
| WebView process terminated (Xcode console) | WKWebView content process killed (memory) | Trap 1/2: lower peak memory, persist state. |
| Android logcat Render process ... gone / app exits after heavy page | Renderer crashed or killed | Reduce memory; implement handling via a WebViewListener onRenderProcessGone if recovery is required. |
| ANR in <appId> (logcat) | Main thread blocked > 5 s, often heavy plugin work on UI thread | Move native work off main thread in custom plugins; profile with Android Studio. |
| Message from debugger: Terminated due to memory issue | iOS jetsam killed the whole app | Allocations instrument; reduce image decoding and caches. |
| Logcat error about the WebView version being below minWebViewVersion | Device WebView too old | Ask user to update Android System WebView; show server.errorPath page. |
Only load when needed:
references/profiling.md: step-by-step traces (Safari Timelines, Chrome Performance, Instruments templates, Android Profiler, adb commands) and how to read them.Weekly roundup of top Claude Code skills, MCP servers, and AI coding tips.