Chrome Extension Performance Optimization — Developer Guide

3 min read

Performance Optimization for Chrome Extensions

Introduction

Service Worker Performance

// GOOD: defer until needed let cachedConfig; async function getConfig() { if (!cachedConfig) cachedConfig = await fetch(“https://api.example.com/config”); return cachedConfig; }


## Bundle Size Optimization {#bundle-size-optimization}
- Use Webpack/Vite/Rollup with tree-shaking enabled
- Analyze bundle: `webpack-bundle-analyzer` or `rollup-plugin-visualizer`
- Code split: dynamic `import()` for features not needed at startup
- Minify production builds (but don't obfuscate — CWS rejects obfuscated code)
- Target: background bundle < 100KB, content scripts < 50KB

## Storage Performance {#storage-performance}
- `chrome.storage` is async and involves IPC — minimize calls
- Use `@theluckystrike/webext-storage` batch operations:
  ```typescript
  // BAD: 5 separate storage calls
  const a = await storage.get('a');
  const b = await storage.get('b');

  // GOOD: single call
  const { a, b } = await storage.getMany(['a', 'b']);

  // GOOD: get everything at once for settings pages
  const all = await storage.getAll();

Content Script Performance

Message Passing Performance

Memory Management

Popup/Options Performance

Network Performance

Profiling Tools

Performance Checklist

Part of the Chrome Extension Guide by theluckystrike. Built at zovo.one.