Article Title
Content visible immediately...
{editing && (
}>
)}
}>
)
}
```
---
### 5. Defer Third-Party Scripts
**Impact: HIGH** — Analytics, tracking, and widgets shouldn't block rendering.
Load non-critical third-party scripts after the page is interactive.
**Avoid — blocks initial render:**
```tsx
// main.tsx
import * as Sentry from '@sentry/react'
import posthog from 'posthog-js'
Sentry.init({ dsn: '...' })
posthog.init('...')
```
**Prefer — load after hydration/mount:**
```tsx
// main.tsx — defer to idle time
function initThirdParty() {
import('@sentry/react').then(Sentry => {
Sentry.init({ dsn: import.meta.env.VITE_SENTRY_DSN })
})
import('posthog-js').then(({ default: posthog }) => {
posthog.init(import.meta.env.VITE_POSTHOG_KEY)
})
}
if ('requestIdleCallback' in window) {
requestIdleCallback(initThirdParty)
} else {
setTimeout(initThirdParty, 2000)
}
```
For external script tags, use `defer` or dynamically inject them:
```typescript
function loadScript(src: string) {
const script = document.createElement('script')
script.src = src
script.async = true
document.body.appendChild(script)
}
```
---
### 6. Preload Critical Assets on User Intent
**Impact: MEDIUM** — Eliminates perceived latency on navigation.
Start loading a route's code when the user signals intent (hover, focus) rather than waiting for the click.
```tsx
function NavLink({ to, children }: { to: string; children: React.ReactNode }) {
const preload = () => {
// Vite creates a module preload for dynamic imports
switch (to) {
case '/dashboard':
import('./pages/Dashboard')
break
case '/settings':
import('./pages/Settings')
break
}
}
return (