/** * Prefetching Configuration Examples * * Use these configurations with startRouter() or directly with LinkPrefetcher */ // Default configuration - balanced performance export const defaultConfig = { strategies: ['hover', 'visible'], // Prefetch on hover and when visible hoverDelay: 150, // Wait 150ms before prefetching on hover observerMargin: '50px', // Start prefetching when link is 50px from viewport maxCacheSize: 20, // Cache up to 20 pages cacheTTL: 60000, // Cache for 60 seconds priority: 'low' // Use low priority for network requests }; // Aggressive prefetching - for fast networks export const aggressiveConfig = { strategies: ['hover', 'visible', 'eager'], hoverDelay: 50, // Faster hover response observerMargin: '200px', // Prefetch earlier maxCacheSize: 50, // Larger cache cacheTTL: 300000, // Cache for 5 minutes priority: 'high' // High priority requests }; // Conservative prefetching - for slow networks or mobile export const conservativeConfig = { strategies: ['hover'], // Only prefetch on hover hoverDelay: 300, // Wait longer before prefetching observerMargin: '0px', // Don't use intersection observer maxCacheSize: 10, // Smaller cache cacheTTL: 30000, // Cache for 30 seconds priority: 'low' // Low priority }; // Minimal prefetching - disabled by default export const minimalConfig = { strategies: [], // No automatic prefetching maxCacheSize: 5, // Minimal cache cacheTTL: 15000, // Short cache duration }; // Adaptive configuration based on connection export function getAdaptiveConfig() { // Use Network Information API if available const connection = navigator.connection || navigator.mozConnection || navigator.webkitConnection; if (!connection) { return defaultConfig; } // Check effective connection type if (connection.effectiveType === '4g' && !connection.saveData) { return aggressiveConfig; } else if (connection.effectiveType === '3g' || connection.saveData) { return conservativeConfig; } else if (connection.effectiveType === '2g' || connection.effectiveType === 'slow-2g') { return minimalConfig; } return defaultConfig; } // Custom configuration for specific pages export function getPageSpecificConfig(pathname) { // Disable prefetching on certain pages if (pathname.includes('/admin') || pathname.includes('/checkout')) { return minimalConfig; } // Aggressive prefetching on landing pages if (pathname === '/' || pathname === '/products') { return aggressiveConfig; } return defaultConfig; }