What is Lighthouse?
- Open-source auditing tool built into Chrome DevTools.
- Provides reports on:
- Performance
- Accessibility
- Best Practices
- SEO
- Progressive Web Apps (PWA)
Running Lighthouse
- Open Chrome → DevTools (F12).
- Go to Lighthouse tab.
- Choose categories (Performance, SEO, etc.).
- Select device (Mobile or Desktop).
- Run the audit → Get a score (0–100).
Common Performance Bottlenecks
- Large JS Bundles
- Fix: Code splitting, tree shaking.
- Unoptimized Images
- Fix: Use WebP/AVIF, responsive images.
- Render-blocking resources
- Fix: Defer non-critical JS, preload critical CSS.
<link rel="preload" href="/styles.css" as="style"> <script src="/app.js" defer></script>
- Too many network requests
- Fix: Bundle files, use caching/CDN.
CI/CD Integration with Lighthouse
Run Lighthouse in GitHub Actions:
# .github/workflows/lighthouse.yml
name: Lighthouse CI
on: [push]
jobs:
audit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: treosh/lighthouse-ci-action@v9
with:
urls: "https://example.com"
configPath: "./lighthouserc.json"
Best Practices
- Aim for 90+ scores in performance & accessibility.
- Use Lighthouse CI in pipelines.
- Test both desktop & mobile views.