import { createRoot } from 'react-dom/client'
import { Suspense } from 'react'
import App from './App.tsx'
import './index.css'
// TypeScript declarations for performance tracking
declare global {
interface Window {
__PERF_START__?: number;
gtag?: (...args: any[]) => void;
}
}
// Preload critical modules
const criticalModules = [
() => import('./components/Navigation.tsx'),
() => import('./components/Calculator.tsx'),
() => import('./components/ThemeProvider.tsx'),
() => import('./components/SEOHead.tsx'),
() => import('./components/LazyImage.tsx')
];
// Preload critical CSS and resources
const preloadResources = () => {
// Preload critical fonts
const fontLink = document.createElement('link');
fontLink.rel = 'preload';
fontLink.href = 'https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;600;700&display=swap';
fontLink.as = 'style';
fontLink.onload = () => {
fontLink.rel = 'stylesheet';
};
document.head.appendChild(fontLink);
// Preconnect to external domains
const preconnectDomains = [
'https://fonts.googleapis.com',
'https://fonts.gstatic.com'
];
preconnectDomains.forEach(domain => {
const link = document.createElement('link');
link.rel = 'preconnect';
link.href = domain;
if (domain.includes('gstatic')) {
link.crossOrigin = 'anonymous';
}
document.head.appendChild(link);
});
};
// Preload critical modules and resources in the background
if ('requestIdleCallback' in window) {
window.requestIdleCallback(() => {
preloadResources();
criticalModules.forEach(moduleLoader => {
moduleLoader().catch(() => {
// Silently handle preload errors
});
});
});
} else {
// Fallback for browsers without requestIdleCallback
setTimeout(() => {
preloadResources();
criticalModules.forEach(moduleLoader => {
moduleLoader().catch(() => {
// Silently handle preload errors
});
});
}, 1);
}
// Initialize i18n asynchronously with performance monitoring
import('./i18n/config').then(() => {
const root = createRoot(document.getElementById("root")!);
// Mark DOM ready for performance tracking
if (window.__PERF_START__) {
const domReadyTime = performance.now() - window.__PERF_START__;
console.log(`🚀 DOM Ready: ${domReadyTime.toFixed(2)}ms`);
}
root.render(
Subnet Calculator failed to load. Please refresh the page.