thedaviddias/Front-End-Checklist / skills/js-file-size
js-file-size
VerifiedUse when auditing slow page loads, heavy assets, or rendering delays related to Optimize JavaScript bundle size. Verify the actual bottleneck in DevTools, Lighthouse, or field data before recommending changes.
| File | Kind | Size |
|---|---|---|
| SKILL.md | skill md | 1.6 KB |
| references/rule.md | markdown | 2.3 KB |
references/rule.md
View on GitHub# Optimize JavaScript bundle size
> Checks for JavaScript files that exceed recommended size limits to ensure fast interaction
**Priority:** medium · **Difficulty:** intermediate · **Time:** 10 min
---
Excessive JavaScript is one of the biggest contributors to poor web performance. Unlike images, which only need to be decoded, JavaScript must be downloaded, parsed, compiled, and executed.
## Code Examples
#
## Using Dynamic Imports (Next.js/React)
```jsx
const HeavyComponent = dynamic(() => import('./HeavyComponent'), {
loading: () => <p>Loading...</p>,
})
return (
<div>
</div>
)
}
```
### Tree Shaking (ES Modules)
```javascript
// ✅ Good: Import only what you need
// ❌ Bad: Import the whole library
// Use instead: import debounce from 'lodash/debounce';
```
## Why It Matters
- **Main Thread Blocking**: JavaScript execution happens on the main thread, blocking user interactions.
- **Device Disparity**: A 1MB script might take 1s to parse on a flagship phone but 10s on a budget device.
- **Data Usage**: Larger files consume more of the user's data plan, which is critical for users on metered connections.
- **SEO Impact**: Slow interaction metrics (FID/INP) are part of Google's Core Web Vitals and can affect search rankings.
## Best Practices
✅ **Code Splitting**: Break large bundles into smaller, page-specific chunks.
✅ **Tree Shaking**: Ensure your build tool (Webpack, Vite, Rollup) is removing unused exports.
✅ **Audit Dependencies**: Use tools like `bundle-analyzer` to find "heavy" libraries.
✅ **Compression**: Always serve JS with Gzip or Brotli compression.
## Tools & Validation
- [BundleAnalyzer](https://www.npmjs.com/package/webpack-bundle-analyzer)
- [Lighthouse](https://developers.google.com/web/tools/lighthouse)
- [BundlePhobia](https://bundlephobia.com/)
- Browser DevTools Coverage tab
## Verification
### Automated Checks
- Measure the affected page or flow in Lighthouse, PageSpeed Insights, or DevTools and confirm the targeted metric improves.
- Inspect the network waterfall or performance timeline to confirm the intended resource or execution change actually took effect.
### Manual Checks
- Verify the change on a throttled mobile profile, not just local desktop.
- If this rule maps to a budget or Web Vital, confirm the page now stays within that threshold.Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| rea-analysis-optimizationmorluto/reaOptimize REA providers and shared analysis workflows for agent context, latency, CPU, and memory while preserving correctness and Evidence. Use for analysis bottlenecks and cache or query design; CI/test-suite optimization belongs to rea-ci-tests-audit. | Stars: 472k | Updated | Claude CodeCodex | Verified | Install |
| rea-ci-tests-auditmorluto/reaAudit REA CI and test suites for correctness, fixture drift, false passes, and measured performance; use for suite or workflow investigations and efficiency changes, rather than ordinary feature testing or a single test failure. | Stars: 472k | Updated | Claude CodeCodex | Verified | Install |
| rea-tool-designmorluto/reaAudit, investigate, design, or change REA investigation tools, CLI/MCP contracts, provider capabilities, and Evidence semantics. | Stars: 472k | Updated | Claude CodeCodex | Verified | Install |
| ponytail-auditDietrichGebert/ponytailQuality audit of the whole repo: bugs, security, real load, missing tests, speed, and what to delete. Most important first. | Stars: 194k | Updated | Claude CodeCodex | Verified | Install |