bundle-defer-third-party — Claude Code rule: setup guide
bundle-defer-third-party prevents third-party trackers from inflating the initial bundle. It instructs the assistant to load analytics and monitoring after hydration.
MIT ★ 7,191 updated 2026-10-24
.claude/rules/bundle-defer-third-party.mdWhat bundle-defer-third-party does
This guideline stops non-critical external libraries from blocking user interactions. Code for analytics, logging, and error monitoring does not need to execute before the first paint, so it should stay out of the initial payload.
Instead of direct imports like @vercel/analytics/react inside RootLayout, the assistant switches to dynamic imports. In Next.js setups, it uses next/dynamic with { ssr: false }, fetching the tracking component only after page hydration finishes.
The pattern relies directly on next/dynamic. For frontends running outside Next.js, the implementation details require manual adjustment to your bundler.
What it helps with
- Keep heavy tracking libraries out of the initial JavaScript bundle
- Load
@vercel/analytics/reactdynamically after client hydration - Prevent third-party logging tools from delaying page responsiveness
- Disable server-side rendering for non-essential monitoring widgets
Example prompts for the agent
- Inspect
RootLayoutand defer all non-critical third-party scripts - Refactor our
@vercel/analytics/reactimport to load after hydration - Update analytics imports in Next.js to use dynamic loading without SSR
How to install bundle-defer-third-party
Manually: put the files in place
.claude/rules/bundle-defer-third-party.mdThe paths frontmatter field limits the files
AGENTS.md
Codex reads AGENTS.md: paste the rule text there
Manually: put the files in place
.cursor/rules/bundle-defer-third-party.mdcFrontmatter: description, globs, alwaysApply
Manually: put the files in place
.github/instructions/bundle-defer-third-party.instructions.mdThe applyTo field sets which files it applies to
Manually: put the files in place
.devin/rules/bundle-defer-third-party.mdManually: put the files in place
.clinerules/bundle-defer-third-party.mdStep by step, with commands for each platform: AGENTS.md vs CLAUDE.md: what they are and which one to use
Questions about bundle-defer-third-party
How to install bundle-defer-third-party in Claude Code?
Save the rule file to .claude/rules/bundle-defer-third-party.md in your project folder.
What does bundle-defer-third-party do?
It guides the agent to defer non-essential dependencies like tracking and logging until the hydration step is complete.
Which bundler setup does this rule target?
Its reference snippet uses next/dynamic from Next.js with { ssr: false } to postpone mounting components.
Source text
bundle-defer-third-party.md · MIT
---
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>
)
}
```
© tech-leads-club · MIT · tech-leads-club/agent-skills