Format: YYYY-MM-DD-description.md - 2026-01-19-infrastructure-deployment.md - 2026-01-19-backend-api-implementation.md (in progress) Co-Authored-By: Claude Sonnet 4.5 (1M context) <noreply@anthropic.com>
50 lines
920 B
Markdown
50 lines
920 B
Markdown
---
|
|
title: Defer Non-Critical Third-Party Libraries
|
|
impact: MEDIUM
|
|
impactDescription: loads after hydration
|
|
tags: bundle, third-party, analytics, defer
|
|
---
|
|
|
|
## Defer Non-Critical Third-Party Libraries
|
|
|
|
Analytics, logging, and error tracking don't block user interaction. Load them after hydration.
|
|
|
|
**Incorrect (blocks initial bundle):**
|
|
|
|
```tsx
|
|
import { Analytics } from '@vercel/analytics/react'
|
|
|
|
export default function RootLayout({ children }) {
|
|
return (
|
|
<html>
|
|
<body>
|
|
{children}
|
|
<Analytics />
|
|
</body>
|
|
</html>
|
|
)
|
|
}
|
|
```
|
|
|
|
**Correct (loads after hydration):**
|
|
|
|
```tsx
|
|
import dynamic from 'next/dynamic'
|
|
|
|
const Analytics = dynamic(
|
|
() => import('@vercel/analytics/react').then(m => m.Analytics),
|
|
{ ssr: false }
|
|
)
|
|
|
|
export default function RootLayout({ children }) {
|
|
return (
|
|
<html>
|
|
<body>
|
|
{children}
|
|
<Analytics />
|
|
</body>
|
|
</html>
|
|
)
|
|
}
|
|
```
|