Skip to main content
rule CX Codex

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

Install into Claude Code · Manually: put the files in place All methods and platforms ↓
.claude/rules/bundle-defer-third-party.md
Open on GitHub

What 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/react dynamically 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 RootLayout and defer all non-critical third-party scripts
  • Refactor our @vercel/analytics/react import 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.md

The paths frontmatter field limits the files

Step 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

Similar IDE rules

All IDE rules for Frontend and UI →
third-party patterns.dev Teaches how to reduce the performance impact of third-party scripts. Kicks in when working with analytics, ads, chat widgets or embedded maps. CX Codex +1 1,700installs next-bundle-optimizer vercel next-bundle-optimizer audits the initial browser work of a Next.js app: slow route startup, oversized client bundles, duplicate dependencies, features that could wait for interaction. CX Codex +1 4,800installs bundle-analyzable-paths fcakyon The bundle-analyzable-paths rule recommends making import and file paths statically analyzable. That keeps bundlers from treating a broad set of files as reachable. CX Codex +1 ★ 1,216repo stars bundle-dynamic-imports jarrodwatts bundle-dynamic-imports guides Claude Code to lazy-load heavy components using next/dynamic with SSR disabled. Keeps your initial client bundle lean to protect TTI and LCP metrics. CX Codex +1 ★ 1,064repo stars agentic-bundle-aas-accessibility-inclusive-ux sickn33 and contributors agentic-bundle-aas-accessibility-inclusive-ux is a Claude Code plugin for an editorial skill bundle about accessibility and inclusive UX. Its subject is relevant to work that addresses either topic. CX Codex ★ 50,109repo stars agentic-bundle-aas-mobile-app-builder sickn33 and contributors agentic-bundle-aas-mobile-app-builder — a curated skill bundle for mobile app development in Claude Code. Includes ready-to-use tools and templates to accelerate the creation of functional mobile solutions. CX Codex ★ 50,109repo stars

From the same set130

The whole set →
seo Walks Claude through technical and on-page SEO: crawl rules, canonicals, sitemaps, meta tags, JSON-LD. Useful when pages don't get indexed or snippets look broken. CX Codex +1 ★ 7,191repo stars best-practices best-practices is a Claude Code skill for checking web code security, browser compatibility, and code quality. It runs on requests for a security review or code modernization. CX Codex +1 ★ 7,191repo stars js-index-maps The js-index-maps rule replaces repeated .find() calls on one key with a Map index. Use it when array lookups happen many times. CX Codex +1 ★ 7,191repo stars rendering-hydration-suppress-warning rendering-hydration-suppress-warning silences hydration warnings where the two renders are meant to differ: timestamps, per-render IDs, dates formatted for the visitor's locale. CX Codex +1 ★ 7,191repo stars bundle-conditional The bundle-conditional rule recommends loading large modules only when their feature is activated. It applies to lazy-loaded data and browser-only code in SSR builds. CX Codex +1 ★ 7,191repo stars react19-no-forwardref react19-no-forwardref is a Claude Code rule covering React 19 ref and context changes: pass ref as a prop and use use() instead of useContext(). It supports React 19 migrations. CX Codex +1 ★ 7,191repo stars advanced-init-once advanced-init-once prevents running app-wide startup logic inside component useEffect([]) hooks and suggests module-level guards or top-level initialization instead. CX Codex +1 ★ 7,191repo stars rerender-defer-reads The rerender-defer-reads rule keeps callback-only reads of dynamic state out of component subscriptions. Use it when searchParams or localStorage is needed only after an action. CX Codex +1 ★ 7,191repo stars

Project sponsors

Companies that keep this analytics open