Skip to content

Conversation

@chuchihoney3
Copy link
Owner

Related GitHub Issue

Closes: #

Roo Code Task Context (Optional)

Description

This PR optimizes initial page load performance by converting the PostHog analytics bundle to a client-only, code-split chunk using Next.js dynamic import.

Previously, the ~45-60 KB PostHog bundle was statically imported into the main JS chunk, delaying first paint. By making it a dynamic import with ssr: false, the bundle is now fetched after the page is interactive, significantly shrinking the initial bundle size and improving First Contentful Paint (FCP) and Time To Interactive (TTI).

Test Procedure

To verify these changes:

  1. Build and run the application locally.
  2. Open your browser's developer tools (e.g., Chrome DevTools) and navigate to the "Network" tab.
  3. Load any page in the application.
  4. Observe that the PostHog analytics bundle (e.g., posthog-js-*.js) is loaded after the initial critical JavaScript bundle, typically a few seconds after the page becomes interactive.
  5. Confirm that the initial JavaScript payload size is reduced compared to the previous static import.

Pre-Submission Checklist

  • Issue Linked: This PR is linked to an approved GitHub Issue (see "Related GitHub Issue" above).
  • Scope: My changes are focused on the linked issue (one major feature/fix per PR).
  • Self-Review: I have performed a thorough self-review of my code.
  • Testing: New and/or updated tests have been added to cover my changes (if applicable).
  • Documentation Impact: I have considered if my changes require documentation updates (see "Documentation Updates" section below).
  • Contribution Guidelines: I have read and agree to the Contributor Guidelines.

Screenshots / Videos

Documentation Updates

  • No documentation updates are required.

Additional Notes

This change is part of a broader performance optimization effort. Further opportunities identified include:

  1. Recharts & Charts: Lazy-loading the Recharts bundle (140-180 KB) and importing only required primitives.
  2. Icons: Switching to lucide-react or enabling Babel’s modularizeImports for react-icons.
  3. Framer Motion: Lazy-loading Framer Motion components (~70 KB) on pages that use animations.
  4. Tailwind purging: Optimizing tailwind.config.ts to avoid scanning node_modules.
  5. Images/Fonts: Replacing <img> with next/image and using next/font for Google Fonts.
  6. Build-time tooling: Utilizing NEXT_JS_ANALYZE=true and experimental.optimizePackageImports.

This PR delivers an immediate ~50 KB reduction in initial JS, with the potential for an additional 250-300 KB savings from the other identified opportunities.

Get in Touch


Open in Cursor Open in Web

Learn more about Cursor Agents

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants