import React, { Suspense, lazy } from "react"; import ReactDOM from "react-dom/client"; import { HelmetProvider } from "react-helmet-async"; import { BrowserRouter as Router, Routes, Route } from "react-router-dom"; import "./index.css"; import Layout from "./components/Layout"; import Loader from "./components/Loader"; import ScrollToTop from "./components/ScrollToTop"; import ErrorBoundary from "./components/ErrorBoundary"; import { initAllAnalytics } from "./utils/deferredAnalytics"; import { initPWAFeatures } from "./utils/pwaFeatures"; // ========================================== // Core Web Vitals Monitoring (Production) // ========================================== const initCoreWebVitals = async () => { try { if (process.env.NODE_ENV === "production") { const { getCLS, getFID, getFCP, getLCP, getTTFB } = await import( "web-vitals" ); getCLS((metric) => { if (metric.value > 0.1) console.warn("⚠️ CLS:", metric.value); }); getFID((metric) => { if (metric.value > 100) console.warn("⚠️ FID:", metric.value); }); getLCP((metric) => { if (metric.value > 2500) console.warn("⚠️ LCP:", metric.value); }); getTTFB((metric) => { console.log("TTFB:", metric.value); }); } } catch (error) { console.error("Web Vitals monitoring error:", error); } }; // Initialize performance monitoring if (process.env.NODE_ENV === "production") { initCoreWebVitals(); } // Lazy load components for better performance const Home = lazy(() => import("./pages/Home")); const Work = lazy(() => import("./pages/Work")); const ProjectDetail = lazy(() => import("./pages/ProjectDetail")); const About = lazy(() => import("./pages/About")); const Contact = lazy(() => import("./pages/Contact")); const DeveloperHub = lazy(() => import("./pages/DeveloperHub")); const FAQ = lazy(() => import("./pages/FAQ")); const NotFound = lazy(() => import("./pages/NotFound")); // Preload critical components with optimized strategy const preloadComponents = async () => { const routes = [ () => import("./pages/Home"), () => import("./pages/Work"), () => import("./pages/About"), () => import("./pages/Contact"), ]; try { // Preload most critical routes first await Promise.all(routes.slice(0, 2).map((route) => route())); // Preload remaining routes after a delay to avoid blocking await new Promise((resolve) => { setTimeout(async () => { try { await Promise.all(routes.slice(2).map((route) => route())); } catch (err) { console.warn("Failed to preload remaining components:", err); } resolve(); }, 1500); }); } catch (error) { console.warn("Failed to preload some components:", error); } }; // Enhanced Suspense fallback with better UX const LoadingFallback = () => (
Loading...