vite-plugin-smart-prefetch 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +605 -0
- package/dist/index.cjs +1783 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +211 -0
- package/dist/index.d.ts +211 -0
- package/dist/index.js +1746 -0
- package/dist/index.js.map +1 -0
- package/dist/react/index.cjs +798 -0
- package/dist/react/index.cjs.map +1 -0
- package/dist/react/index.d.cts +175 -0
- package/dist/react/index.d.ts +175 -0
- package/dist/react/index.js +758 -0
- package/dist/react/index.js.map +1 -0
- package/dist/runtime/index.cjs +678 -0
- package/dist/runtime/index.cjs.map +1 -0
- package/dist/runtime/index.d.cts +223 -0
- package/dist/runtime/index.d.ts +223 -0
- package/dist/runtime/index.js +645 -0
- package/dist/runtime/index.js.map +1 -0
- package/package.json +67 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/runtime/index.ts","../../src/runtime/prefetch-manager.ts","../../src/runtime/debug-utils.ts"],"sourcesContent":["/**\n * Runtime exports for client-side code\n * These exports have NO dependencies on server-side packages like firebase-admin\n */\n\nexport { PrefetchManager } from './prefetch-manager';\n\n// Debug utilities\nexport {\n getPrefetchLinks,\n getPluginPrefetchLinks,\n logPrefetchLinks,\n monitorPrefetchActivity,\n checkPluginConfiguration,\n exposeDebugUtils,\n} from './debug-utils';\n\n// Re-export types that are safe for client-side use\nexport type {\n PrefetchStrategy,\n PrefetchConfig,\n PrefetchTarget,\n} from '../types';\n","/**\n * Prefetch Manager (Runtime)\n * Manages route prefetching in the browser\n */\n\nimport type { PrefetchConfig, PrefetchStrategy, PrefetchTarget } from '../types';\n\nexport class PrefetchManager {\n private config: PrefetchConfig | null = null;\n private prefetched = new Set<string>();\n private strategy: PrefetchStrategy;\n private observer: IntersectionObserver | null = null;\n private debug: boolean;\n private currentSegment: string | null = null;\n private fallbackToDefault: boolean = true;\n\n constructor(strategy: PrefetchStrategy = 'hybrid', debug = false) {\n this.strategy = strategy;\n this.debug = debug;\n }\n\n /**\n * Initialize the prefetch manager\n * Loads configuration and sets up observers\n */\n async init(): Promise<void> {\n if (this.debug) {\n console.log('š Smart Prefetch Manager - Initializing...');\n console.log(' Strategy:', this.strategy);\n console.log(' Debug mode: enabled');\n }\n\n try {\n // Load prefetch configuration\n if (this.debug) {\n console.log('š„ Fetching prefetch-config.json...');\n }\n\n const response = await fetch('/prefetch-config.json');\n\n // Gracefully handle missing config file (common in development)\n if (!response.ok) {\n if (response.status === 404) {\n if (this.debug) {\n console.warn('ā ļø Prefetch config not found (404)');\n console.log(' This is expected if:');\n console.log(' 1. You haven\\'t built the app yet (run `pnpm build`)');\n console.log(' 2. The plugin failed to generate the config during build');\n console.log(' Prefetch manager will be inactive until config is available');\n }\n return;\n }\n throw new Error(`Failed to load prefetch config: ${response.statusText}`);\n }\n\n this.config = await response.json();\n\n if (this.debug && this.config) {\n console.log('ā
Config loaded successfully');\n console.log(` Routes with prefetch rules: ${Object.keys(this.config.routes).length} ${typeof this.config.routes}`);\n console.log(` Environment: ${this.config.environment}`);\n console.log(` Config version: ${this.config.version || 'N/A'}`);\n\n // List all routes with prefetch rules\n console.groupCollapsed('š Available prefetch rules:');\n Object.entries(this.config.routes).forEach(([source, data]: [string, any]) => {\n console.log(`${source} ā ${data.prefetch.length} target(s)`,\n data.prefetch.map((t: any) => t.route));\n });\n console.groupEnd();\n }\n\n // Set up intersection observer for 'visible' strategy\n if (this.strategy === 'visible' || this.strategy === 'hybrid') {\n this.initIntersectionObserver();\n if (this.debug) {\n console.log('šļø IntersectionObserver initialized for visibility-based prefetching');\n }\n }\n\n if (this.debug) {\n console.log('ā
Prefetch Manager fully initialized');\n console.log('š” Run window.__PREFETCH_DEBUG__() to see current state');\n\n // Expose debug helper globally\n (window as any).__PREFETCH_DEBUG__ = () => this.logDebugInfo();\n }\n } catch (error) {\n // Only log error if debug mode is enabled\n if (this.debug) {\n console.error('ā Failed to initialize Prefetch Manager:', error);\n }\n }\n }\n\n /**\n * Set the user segment for segment-based prefetch rules\n * @param segment - The user's segment (e.g., 'premium', 'free', 'admin')\n * @param fallbackToDefault - Use default rules if segment rules unavailable\n */\n setSegment(segment: string | null, fallbackToDefault: boolean = true): void {\n this.currentSegment = segment;\n this.fallbackToDefault = fallbackToDefault;\n\n if (this.debug) {\n console.log(`š Segment updated: ${segment || '(none)'}`);\n console.log(` Fallback to default: ${fallbackToDefault}`);\n }\n }\n\n /**\n * Get the current segment\n */\n getSegment(): string | null {\n return this.currentSegment;\n }\n\n /**\n * Prefetch routes based on current route\n */\n prefetch(currentRoute: string): void {\n // Strip query parameters and hash from the route\n const cleanRoute = currentRoute.split('?')[0].split('#')[0];\n\n if (this.debug) {\n console.log(`š Checking prefetch for route: ${currentRoute}`);\n if (currentRoute !== cleanRoute) {\n console.log(` Clean route: ${cleanRoute}`);\n }\n }\n\n if (!this.config) {\n if (this.debug) {\n console.warn('ā ļø Config not loaded yet - cannot prefetch');\n console.log(' Make sure the app was built with the plugin enabled');\n }\n return;\n }\n\n // Check network conditions\n if (!this.shouldPrefetch()) {\n if (this.debug) {\n console.log('āļø Skipping prefetch due to network conditions');\n }\n return;\n }\n\n // Try to find route config (try both clean and original route)\n let routeConfig = this.config.routes[cleanRoute] || this.config.routes[currentRoute];\n const matchedRoute = routeConfig ? (this.config.routes[cleanRoute] ? cleanRoute : currentRoute) : null;\n\n if (!routeConfig) {\n if (this.debug) {\n console.warn(`ā ļø No prefetch rules configured for route: ${cleanRoute}`);\n console.groupCollapsed('Available routes in config:');\n Object.keys(this.config.routes).forEach(route => {\n const targets = this.config!.routes[route].prefetch;\n console.log(` ${route} ā ${targets.length} target(s)`, targets.map(t => t.route));\n });\n console.groupEnd();\n console.log(`š” Tip: Make sure your manualRules key matches exactly: \"${cleanRoute}\"`);\n }\n return;\n }\n\n // Determine which rules to use: segment-specific or default\n let prefetchTargets = routeConfig.prefetch;\n let ruleSource = 'default';\n\n // Check if segment-specific rules are available and configured\n if (this.currentSegment && routeConfig.segments?.[this.currentSegment]) {\n prefetchTargets = routeConfig.segments[this.currentSegment];\n ruleSource = `segment (${this.currentSegment})`;\n } else if (this.currentSegment && !routeConfig.segments?.[this.currentSegment] && !this.fallbackToDefault) {\n // Segment specified but no rules for it and fallback disabled\n if (this.debug) {\n console.warn(`ā ļø No prefetch rules for segment \"${this.currentSegment}\" and fallback disabled`);\n }\n return;\n }\n\n // Always log when a route is found and prefetch is about to happen\n console.log(`ā
Found prefetch rule for: ${matchedRoute}`);\n console.log(` Total targets to prefetch: ${prefetchTargets.length}`);\n console.log(` Using: ${ruleSource} rules`);\n console.log(` Strategy: ${this.strategy}`);\n\n if (this.debug) {\n console.groupCollapsed(`š Prefetch Rules for: ${matchedRoute} (${ruleSource})`);\n prefetchTargets.forEach((target, index) => {\n console.log(` ${index + 1}. ${target.route} (${target.priority} priority, ${(target.probability * 100).toFixed(1)}%)`);\n });\n console.groupEnd();\n }\n\n // Prefetch based on strategy\n prefetchTargets.forEach((target) => {\n this.prefetchTarget(target);\n });\n }\n\n /**\n * Prefetch a specific target\n */\n private prefetchTarget(target: any): void {\n // Check if already prefetched\n if (this.prefetched.has(target.route)) {\n console.log(` āļø Already prefetched: ${target.route}`);\n return;\n }\n\n console.log(` š Prefetch target: ${target.route}, chunk: ${target.chunk}`);\n\n try {\n // Apply strategy-based prefetching\n switch (this.strategy) {\n case 'auto':\n this.injectPrefetchLink(target);\n break;\n\n case 'hover':\n // Hover is handled by link components\n break;\n\n case 'visible':\n // Visible is handled by IntersectionObserver\n break;\n\n case 'idle':\n this.prefetchOnIdle(target);\n break;\n\n case 'hybrid':\n this.prefetchHybrid(target);\n break;\n\n default:\n console.warn(`ā ļø Unknown strategy: ${this.strategy}`);\n }\n } catch (error) {\n console.error(`ā Error prefetching ${target.route}:`, error);\n }\n }\n\n /**\n * Hybrid strategy: prioritize based on probability\n * FOR TESTING: Fetch all priorities to verify chunks are correct\n */\n private prefetchHybrid(target: PrefetchTarget & { chunk: string }): void {\n if (target.priority === 'high' || target.probability >= 0.7) {\n // High priority: prefetch immediately\n console.log(` ā” High priority (${(target.probability * 100).toFixed(1)}%) - Prefetching immediately`);\n this.injectPrefetchLink(target);\n } else if (target.priority === 'medium' || target.probability >= 0.4) {\n // Medium priority: prefetch on idle (FOR TESTING: fetch immediately)\n console.log(` ā±ļø Medium priority (${(target.probability * 100).toFixed(1)}%) - Fetching immediately (TESTING MODE)`);\n this.injectPrefetchLink(target); // Changed from prefetchOnIdle to immediate for testing\n } else {\n // Low priority: wait for visibility or hover (FOR TESTING: fetch immediately)\n console.log(` š Low priority (${(target.probability * 100).toFixed(1)}%) - Fetching immediately (TESTING MODE)`);\n this.injectPrefetchLink(target); // Changed from deferred to immediate for testing\n }\n }\n\n /**\n * Prefetch during idle time\n */\n private prefetchOnIdle(target: PrefetchTarget & { chunk: string }): void {\n if ('requestIdleCallback' in window) {\n requestIdleCallback(() => {\n this.injectPrefetchLink(target);\n });\n } else {\n // Fallback for browsers without requestIdleCallback\n setTimeout(() => {\n this.injectPrefetchLink(target);\n }, 1000);\n }\n }\n\n /**\n * Resolve chunk path for the current environment\n * In production: chunks are built with hashes (e.g., chunks/Privacy-D5qJZu-O.js or js/index-CJMMxcQV.js)\n * In dev mode: need to resolve to the actual module or use a proxy\n */\n private resolveChunkPath(chunkPath: string, route: string): string {\n const isDev = window.location.hostname === 'localhost' || window.location.hostname === '127.0.0.1';\n\n if (!isDev) {\n // Production: use the chunk path as-is (it has real hashes from the build)\n return `/${chunkPath}`;\n }\n\n // Dev mode: Try to map chunk to component and use source files\n // Extract component name from chunk path\n // Examples:\n // - chunks/Privacy-D5qJZu-O.js ā Privacy\n // - js/index-CJMMxcQV.js ā index\n // - chunks/chunk-user-profile-JNr_q4Gn.js ā (can't map, use original)\n\n // Try to extract component name from various chunk name patterns\n let componentName: string | null = null;\n\n // Pattern 1: Individual component chunks (e.g., Privacy-D5qJZu-O.js)\n const match1 = chunkPath.match(/\\/([A-Z][a-zA-Z]*)-[a-zA-Z0-9_-]+\\.js$/);\n if (match1) {\n componentName = match1[1];\n }\n\n // Pattern 2: Main/index chunks (e.g., js/index-CJMMxcQV.js)\n const match2 = chunkPath.match(/\\/(index)-[a-zA-Z0-9_-]+\\.js$/);\n if (match2) {\n componentName = match2[1];\n }\n\n if (componentName) {\n // Map component name to source file\n // This works because Vite's dev server resolves source files dynamically\n const sourceFile = componentName === 'index' ? '/src/main.tsx' : `/src/pages/${componentName}.tsx`;\n if (this.debug) {\n console.log(` š Dev mode: Resolved ${chunkPath} ā ${sourceFile}`);\n }\n return sourceFile;\n }\n\n // Fallback: use original chunk path with leading slash\n if (this.debug) {\n console.log(` ā ļø Dev mode: Could not extract component name from ${chunkPath}, using as-is`);\n }\n return `/${chunkPath}`;\n }\n\n /**\n * Inject prefetch link into DOM\n */\n private injectPrefetchLink(target: PrefetchTarget & { chunk: string }): void {\n if (this.prefetched.has(target.route)) {\n if (this.debug) {\n console.log(` āļø Already prefetched: ${target.route}`);\n }\n return;\n }\n\n // Resolve the actual chunk path for the current environment\n // In production: use the chunk hash from config (e.g., chunks/Privacy-D5qJZu-O.js)\n // In dev mode: chunks don't exist as files, Vite handles them at request time\n const chunkPath = this.resolveChunkPath(target.chunk, target.route);\n\n // Create main chunk link\n const link = document.createElement('link');\n // Use modulepreload for better ES module support (triggers actual fetch)\n link.rel = 'modulepreload';\n link.href = chunkPath;\n link.setAttribute('data-prefetch-route', target.route);\n link.setAttribute('data-prefetch-priority', target.priority);\n link.setAttribute('data-prefetch-probability', target.probability.toString());\n\n // Always log prefetch with details\n console.groupCollapsed(`š PREFETCH: ${target.route}`);\n console.log(` š Page/Route: ${target.route}`);\n console.log(` š¦ Main Chunk: ${target.chunk}`);\n console.log(` š Resolved URL: ${window.location.origin}${chunkPath}`);\n console.log(` ā Priority: ${target.priority}`);\n console.log(` š Probability: ${(target.probability * 100).toFixed(1)}%`);\n\n // Track total chunks being fetched\n let totalChunksForThisRoute = 1; // Main chunk\n const injectedLinks: string[] = [];\n\n // Try to append the main link - CRITICAL: this must happen first\n try {\n document.head.appendChild(link);\n injectedLinks.push(target.chunk);\n console.log(` ā
Main chunk link injected: ${target.chunk}`);\n } catch (e) {\n console.error(` ā Failed to inject main chunk link:`, e);\n console.groupEnd();\n return;\n }\n\n // Also prefetch all dependency chunks (imports)\n if (target.imports && target.imports.length > 0) {\n console.log(` š Dependencies (${target.imports.length}):`);\n target.imports.forEach((importChunk, index) => {\n // Skip if already prefetched by another route\n const importId = `import:${importChunk}`;\n if (this.prefetched.has(importId)) {\n console.log(` ${index + 1}. ${importChunk} (already prefetched)`);\n return;\n }\n\n try {\n const importLink = document.createElement('link');\n importLink.rel = 'modulepreload';\n importLink.href = `/${importChunk}`;\n importLink.setAttribute('data-prefetch-import', 'true');\n importLink.setAttribute('data-prefetch-parent', target.route);\n document.head.appendChild(importLink);\n this.prefetched.add(importId);\n totalChunksForThisRoute++;\n injectedLinks.push(importChunk);\n\n console.log(` ${index + 1}. ${importChunk} ā
`);\n } catch (e) {\n console.error(` ${index + 1}. ${importChunk} ā Error:`, e);\n }\n });\n }\n\n // Mark as prefetched\n this.prefetched.add(target.route);\n\n console.log(` ā
Total chunks injected: ${totalChunksForThisRoute}`);\n console.log(` š Overall prefetched count: ${this.prefetched.size}`);\n\n if (this.debug) {\n console.log(` DOM Status: ${injectedLinks.length} link tag(s) added to document.head`);\n console.log(` Injected URLs:`, injectedLinks.map(c => `/${c}`));\n\n // Verify the link was actually added and check if it loaded\n setTimeout(() => {\n const addedLink = document.querySelector(`link[data-prefetch-route=\"${target.route}\"]`);\n if (addedLink) {\n console.log(` āļø DOM Verification: Link exists`);\n console.log(` href:`, (addedLink as HTMLLinkElement).href);\n console.log(` as:`, (addedLink as HTMLLinkElement).getAttribute('as'));\n console.log(` rel:`, (addedLink as HTMLLinkElement).rel);\n\n // Check if link actually triggered a fetch\n if ((addedLink as any).relList?.contains('modulepreload')) {\n console.log(` š Link has modulepreload rel (will fetch)`);\n }\n } else {\n console.error(` ā ERROR: Link tag not found in DOM after 100ms`);\n }\n\n // Verify ALL injected links exist\n console.log(` š Verifying all injected links in head:`);\n document.querySelectorAll('link[data-prefetch-route], link[data-prefetch-import]').forEach((el, idx) => {\n const isMain = el.hasAttribute('data-prefetch-route');\n const parent = isMain ? el.getAttribute('data-prefetch-route') : el.getAttribute('data-prefetch-parent');\n console.log(` ${idx + 1}. ${(el as HTMLLinkElement).href} (parent: ${parent})`);\n });\n }, 50);\n }\n\n console.groupEnd();\n }\n\n /**\n * Check if prefetching should be performed based on network conditions\n */\n private shouldPrefetch(): boolean {\n // Check if Network Information API is available\n const nav = navigator as any;\n const connection = nav.connection || nav.mozConnection || nav.webkitConnection;\n\n if (!connection) {\n // API not available, assume prefetch is OK\n return true;\n }\n\n // Respect Data Saver mode\n if (connection.saveData) {\n if (this.debug) console.log(' ā ļø Data Saver enabled');\n return false;\n }\n\n // Check connection speed\n const slowConnections = ['slow-2g', '2g'];\n if (slowConnections.includes(connection.effectiveType)) {\n if (this.debug) console.log(` ā ļø Slow connection: ${connection.effectiveType}`);\n return false;\n }\n\n // Check if metered connection (conservative approach)\n if (connection.type === 'cellular' && connection.effectiveType !== '4g') {\n if (this.debug) console.log(' ā ļø Metered connection');\n return false;\n }\n\n return true;\n }\n\n /**\n * Initialize IntersectionObserver for 'visible' strategy\n */\n private initIntersectionObserver(): void {\n this.observer = new IntersectionObserver(\n (entries) => {\n entries.forEach((entry) => {\n if (entry.isIntersecting) {\n const route = entry.target.getAttribute('data-prefetch-route');\n if (route && this.config) {\n // Find the target in config\n Object.values(this.config.routes).forEach((routeConfig) => {\n const target = routeConfig.prefetch.find((t) => t.route === route);\n if (target) {\n this.injectPrefetchLink(target);\n }\n });\n }\n }\n });\n },\n {\n rootMargin: '50px', // Start prefetch 50px before element is visible\n }\n );\n }\n\n /**\n * Observe an element for visibility-based prefetching\n */\n observeLink(element: HTMLElement, route: string): void {\n if (this.observer) {\n element.setAttribute('data-prefetch-route', route);\n this.observer.observe(element);\n }\n }\n\n /**\n * Manually trigger prefetch for a specific route\n * Useful for hover events\n */\n prefetchRoute(route: string): void {\n if (!this.config) return;\n\n // Find this route in all route configs\n Object.values(this.config.routes).forEach((routeConfig) => {\n const target = routeConfig.prefetch.find((t) => t.route === route);\n if (target) {\n this.injectPrefetchLink(target);\n }\n });\n }\n\n /**\n * Get prefetch statistics\n */\n getStats(): {\n totalPrefetched: number;\n prefetchedRoutes: string[];\n configLoaded: boolean;\n strategy: PrefetchStrategy;\n } {\n return {\n totalPrefetched: this.prefetched.size,\n prefetchedRoutes: Array.from(this.prefetched),\n configLoaded: this.config !== null,\n strategy: this.strategy,\n };\n }\n\n /**\n * Check if a route has been prefetched\n */\n isPrefetched(route: string): boolean {\n return this.prefetched.has(route);\n }\n\n /**\n * Clear all prefetch state\n */\n clear(): void {\n this.prefetched.clear();\n if (this.observer) {\n this.observer.disconnect();\n }\n }\n\n /**\n * Get all prefetch link elements currently in the DOM\n */\n getActivePrefetchLinks(): HTMLLinkElement[] {\n return Array.from(document.querySelectorAll('link[rel=\"modulepreload\"][data-prefetch-route]'));\n }\n\n /**\n * Log current state for debugging\n */\n logDebugInfo(): void {\n console.group('š Smart Prefetch Debug Info');\n console.log('Strategy:', this.strategy);\n console.log('Config loaded:', this.config !== null);\n console.log('Total prefetch entries:', this.prefetched.size);\n console.log('Prefetched items:', Array.from(this.prefetched));\n\n const links = this.getActivePrefetchLinks();\n console.log('\\nš Active Link Tags in DOM:', links.length);\n\n if (links.length > 0) {\n console.table(links.map(link => ({\n route: link.getAttribute('data-prefetch-route'),\n chunk: link.href.replace(window.location.origin + '/', ''),\n priority: link.getAttribute('data-prefetch-priority'),\n probability: link.getAttribute('data-prefetch-probability'),\n })));\n }\n\n if (this.config) {\n console.log('\\nš Configuration Summary:');\n console.log('Available routes in config:', Object.keys(this.config.routes).length);\n console.log('Config environment:', this.config.environment);\n\n console.group('š All configured routes with prefetch targets:');\n Object.entries(this.config.routes).forEach(([route, data]: [string, any]) => {\n console.group(`${route}`);\n data.prefetch.forEach((t: any, idx: number) => {\n console.log(` ${idx + 1}. ${t.route} (${t.priority}, ${(t.probability * 100).toFixed(1)}%) ā ${t.chunk}`);\n });\n console.groupEnd();\n });\n console.groupEnd();\n\n console.log('\\nš” Current location:', window.location.pathname);\n console.log('š” Clean route:', window.location.pathname.split('?')[0].split('#')[0]);\n }\n\n console.groupEnd();\n }\n\n /**\n * Log all prefetched pages and chunks (summary view)\n */\n logPrefetchSummary(): void {\n const links = this.getActivePrefetchLinks();\n const routeLinks = links.filter(l => !l.getAttribute('data-prefetch-import'));\n const dependencyLinks = links.filter(l => l.getAttribute('data-prefetch-import'));\n\n console.group('š PREFETCH SUMMARY');\n console.log(`Total pages prefetched: ${routeLinks.length}`);\n console.log(`Total dependency chunks: ${dependencyLinks.length}`);\n console.log(`Total overall entries: ${this.prefetched.size}`);\n\n if (routeLinks.length > 0) {\n console.group('š Pages/Routes Prefetched:');\n const pageTable = routeLinks.map(link => ({\n route: link.getAttribute('data-prefetch-route'),\n chunk: link.href.replace(window.location.origin + '/', ''),\n priority: link.getAttribute('data-prefetch-priority'),\n probability: `${link.getAttribute('data-prefetch-probability')}`,\n }));\n console.table(pageTable);\n console.groupEnd();\n }\n\n if (dependencyLinks.length > 0) {\n console.group('š¦ Dependency Chunks Prefetched:');\n const depsTable = dependencyLinks.map(link => ({\n parentRoute: link.getAttribute('data-prefetch-parent'),\n chunk: link.href.replace(window.location.origin + '/', ''),\n }));\n console.table(depsTable);\n console.groupEnd();\n }\n\n console.groupEnd();\n }\n}\n","/**\n * Debug Utilities for Smart Prefetch Plugin\n * Helper functions to inspect and debug prefetch behavior\n */\n\n/**\n * Get all prefetch link elements from the DOM\n */\nexport function getPrefetchLinks(): HTMLLinkElement[] {\n return Array.from(document.querySelectorAll('link[rel=\"prefetch\"]'));\n}\n\n/**\n * Get prefetch links added by our plugin (with data attributes)\n */\nexport function getPluginPrefetchLinks(): HTMLLinkElement[] {\n return Array.from(document.querySelectorAll('link[rel=\"prefetch\"][data-prefetch-route]'));\n}\n\n/**\n * Log all prefetch links in a formatted way\n */\nexport function logPrefetchLinks(): void {\n const allLinks = getPrefetchLinks();\n const pluginLinks = getPluginPrefetchLinks();\n\n console.group('š Prefetch Link Tags in DOM');\n console.log(`Total prefetch links: ${allLinks.length}`);\n console.log(`Plugin-managed links: ${pluginLinks.length}`);\n\n if (pluginLinks.length > 0) {\n console.group('Plugin-managed links:');\n console.table(\n pluginLinks.map((link) => ({\n route: link.getAttribute('data-prefetch-route'),\n href: link.href,\n priority: link.getAttribute('data-prefetch-priority'),\n probability: link.getAttribute('data-prefetch-probability'),\n loaded: link.hasAttribute('data-loaded'),\n }))\n );\n console.groupEnd();\n }\n\n const otherLinks = allLinks.filter((link) => !link.hasAttribute('data-prefetch-route'));\n if (otherLinks.length > 0) {\n console.group('Other prefetch links:');\n console.table(\n otherLinks.map((link) => ({\n href: link.href,\n as: link.getAttribute('as'),\n }))\n );\n console.groupEnd();\n }\n\n console.groupEnd();\n}\n\n/**\n * Monitor prefetch activity in real-time\n */\nexport function monitorPrefetchActivity(): () => void {\n console.log('š Monitoring prefetch activity...');\n console.log('Press the returned stop function to stop monitoring');\n\n const observer = new MutationObserver((mutations) => {\n mutations.forEach((mutation) => {\n mutation.addedNodes.forEach((node) => {\n if (node.nodeName === 'LINK') {\n const link = node as HTMLLinkElement;\n if (link.rel === 'prefetch') {\n console.log('ā New prefetch link added:', {\n route: link.getAttribute('data-prefetch-route') || 'N/A',\n href: link.href,\n priority: link.getAttribute('data-prefetch-priority'),\n });\n }\n }\n });\n\n mutation.removedNodes.forEach((node) => {\n if (node.nodeName === 'LINK') {\n const link = node as HTMLLinkElement;\n if (link.rel === 'prefetch') {\n console.log('ā Prefetch link removed:', {\n route: link.getAttribute('data-prefetch-route') || 'N/A',\n href: link.href,\n });\n }\n }\n });\n });\n });\n\n observer.observe(document.head, {\n childList: true,\n subtree: true,\n });\n\n return () => {\n console.log('š Stopped monitoring prefetch activity');\n observer.disconnect();\n };\n}\n\n/**\n * Check if the smart prefetch plugin is properly configured\n */\nexport function checkPluginConfiguration(): void {\n console.group('š§ Smart Prefetch Plugin Configuration Check');\n\n // Check global config\n const globalConfig = (window as any).__SMART_PREFETCH__;\n if (globalConfig) {\n console.log('ā
Global config found:', globalConfig);\n } else {\n console.warn('ā Global config not found on window.__SMART_PREFETCH__');\n console.log(' The plugin may not be properly configured in vite.config');\n }\n\n // Check if config file is accessible\n fetch('/prefetch-config.json')\n .then((res) => {\n if (res.ok) {\n console.log('ā
prefetch-config.json is accessible');\n return res.json();\n } else {\n throw new Error(`HTTP ${res.status}: ${res.statusText}`);\n }\n })\n .then((config) => {\n console.log('š Config content:', config);\n console.log(` Routes: ${Object.keys(config.routes).length}`);\n console.log(` Environment: ${config.environment}`);\n })\n .catch((error) => {\n console.error('ā Cannot access prefetch-config.json:', error.message);\n console.log(' Make sure to build the app first: pnpm build');\n })\n .finally(() => {\n console.groupEnd();\n });\n\n // Check debug function\n if (typeof (window as any).__PREFETCH_DEBUG__ === 'function') {\n console.log('ā
Debug function available: window.__PREFETCH_DEBUG__()');\n } else {\n console.warn('ā ļø Debug function not available (may not be initialized yet)');\n }\n}\n\n/**\n * Expose all debug utilities globally for console access\n */\nexport function exposeDebugUtils(): void {\n const w = window as any;\n w.__PREFETCH_UTILS__ = {\n getPrefetchLinks,\n getPluginPrefetchLinks,\n logPrefetchLinks,\n monitorPrefetchActivity,\n checkPluginConfiguration,\n };\n\n console.log('š” Debug utilities exposed:');\n console.log(' window.__PREFETCH_UTILS__.getPrefetchLinks()');\n console.log(' window.__PREFETCH_UTILS__.logPrefetchLinks()');\n console.log(' window.__PREFETCH_UTILS__.monitorPrefetchActivity()');\n console.log(' window.__PREFETCH_UTILS__.checkPluginConfiguration()');\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;A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I,MAAM,QAAQ,IAAI,MAAM,KAAK,IAAI,UAAU,EAAE;AAAA,IACzD;AAAA,EACF,CAAC,EACA,KAAK,CAAC,WAAW;AAChB,YAAQ,IAAI,6BAAsB,MAAM;AACxC,YAAQ,IAAI,cAAc,OAAO,KAAK,OAAO,MAAM,EAAE,MAAM,EAAE;AAC7D,YAAQ,IAAI,mBAAmB,OAAO,WAAW,EAAE;AAAA,EACrD,CAAC,EACA,MAAM,CAAC,UAAU;AAChB,YAAQ,MAAM,8CAAyC,MAAM,OAAO;AACpE,YAAQ,IAAI,iDAAiD;AAAA,EAC/D,CAAC,EACA,QAAQ,MAAM;AACb,YAAQ,SAAS;AAAA,EACnB,CAAC;AAGH,MAAI,OAAQ,OAAe,uBAAuB,YAAY;AAC5D,YAAQ,IAAI,8DAAyD;AAAA,EACvE,OAAO;AACL,YAAQ,KAAK,yEAA+D;AAAA,EAC9E;AACF;AAKO,SAAS,mBAAyB;AACvC,QAAM,IAAI;AACV,IAAE,qBAAqB;AAAA,IACrB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAEA,UAAQ,IAAI,oCAA6B;AACzC,UAAQ,IAAI,iDAAiD;AAC7D,UAAQ,IAAI,iDAAiD;AAC7D,UAAQ,IAAI,wDAAwD;AACpE,UAAQ,IAAI,yDAAyD;AACvE;","names":[]}
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
type PrefetchStrategy = 'auto' | 'hover' | 'visible' | 'idle' | 'hybrid';
|
|
2
|
+
interface ModelConfig {
|
|
3
|
+
/** Model type */
|
|
4
|
+
type: 'probability' | 'ml' | 'hybrid';
|
|
5
|
+
/** Minimum probability threshold (0.0 - 1.0, default: 0.3) */
|
|
6
|
+
threshold: number;
|
|
7
|
+
/** Maximum routes to prefetch per page (default: 3) */
|
|
8
|
+
maxPrefetch: number;
|
|
9
|
+
/** How often to update the model */
|
|
10
|
+
updateInterval?: 'build' | 'daily' | 'weekly';
|
|
11
|
+
}
|
|
12
|
+
interface DataSourceMetadata {
|
|
13
|
+
/** Provider name */
|
|
14
|
+
provider: 'bigquery' | 'markov-chain' | 'manual' | string;
|
|
15
|
+
/** Date range analyzed */
|
|
16
|
+
dateRange: string;
|
|
17
|
+
/** Total sessions analyzed */
|
|
18
|
+
totalSessions: number;
|
|
19
|
+
/** Total unique routes found */
|
|
20
|
+
totalRoutes?: number;
|
|
21
|
+
}
|
|
22
|
+
interface PrefetchTarget {
|
|
23
|
+
/** Target route to prefetch */
|
|
24
|
+
route: string;
|
|
25
|
+
/** Probability of transition (0.0 - 1.0) */
|
|
26
|
+
probability: number;
|
|
27
|
+
/** Number of observed transitions */
|
|
28
|
+
count: number;
|
|
29
|
+
/** Chunk file to prefetch (set by config generator) */
|
|
30
|
+
chunk?: string;
|
|
31
|
+
/** Dependency chunks to prefetch (extracted from Vite manifest imports) */
|
|
32
|
+
imports?: string[];
|
|
33
|
+
/** Priority level */
|
|
34
|
+
priority: 'high' | 'medium' | 'low';
|
|
35
|
+
/** Whether this is a manual rule */
|
|
36
|
+
manual?: boolean;
|
|
37
|
+
}
|
|
38
|
+
interface RouteMetadata {
|
|
39
|
+
/** Total transitions from this route */
|
|
40
|
+
totalTransitions: number;
|
|
41
|
+
/** Most common destination */
|
|
42
|
+
topDestination: string;
|
|
43
|
+
/** Average time spent on page (seconds) */
|
|
44
|
+
averageTimeOnPage?: number;
|
|
45
|
+
}
|
|
46
|
+
interface PrefetchConfig {
|
|
47
|
+
/** Schema version */
|
|
48
|
+
version: string;
|
|
49
|
+
/** Generation timestamp */
|
|
50
|
+
generatedAt: string;
|
|
51
|
+
/** Environment */
|
|
52
|
+
environment: string;
|
|
53
|
+
/** Data source info */
|
|
54
|
+
dataSource: DataSourceMetadata;
|
|
55
|
+
/** Model info */
|
|
56
|
+
model: {
|
|
57
|
+
type: ModelConfig['type'];
|
|
58
|
+
threshold: number;
|
|
59
|
+
maxPrefetch: number;
|
|
60
|
+
accuracy?: number;
|
|
61
|
+
};
|
|
62
|
+
/** Route predictions with chunk mappings */
|
|
63
|
+
routes: {
|
|
64
|
+
[sourceRoute: string]: {
|
|
65
|
+
/** Default/common prefetch rules (works for all users) */
|
|
66
|
+
prefetch: Array<PrefetchTarget & {
|
|
67
|
+
chunk: string;
|
|
68
|
+
}>;
|
|
69
|
+
/** Segment-specific rules (different per user segment) */
|
|
70
|
+
segments?: {
|
|
71
|
+
[segmentName: string]: Array<PrefetchTarget & {
|
|
72
|
+
chunk: string;
|
|
73
|
+
}>;
|
|
74
|
+
};
|
|
75
|
+
/** Metadata about this route */
|
|
76
|
+
metadata?: RouteMetadata;
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
/** Quick lookup: route -> chunk file */
|
|
80
|
+
chunks: {
|
|
81
|
+
[route: string]: string;
|
|
82
|
+
};
|
|
83
|
+
/** Available segments (for client-side selection) */
|
|
84
|
+
segmentInfo?: {
|
|
85
|
+
available: string[];
|
|
86
|
+
description?: string;
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Prefetch Manager (Runtime)
|
|
92
|
+
* Manages route prefetching in the browser
|
|
93
|
+
*/
|
|
94
|
+
|
|
95
|
+
declare class PrefetchManager {
|
|
96
|
+
private config;
|
|
97
|
+
private prefetched;
|
|
98
|
+
private strategy;
|
|
99
|
+
private observer;
|
|
100
|
+
private debug;
|
|
101
|
+
private currentSegment;
|
|
102
|
+
private fallbackToDefault;
|
|
103
|
+
constructor(strategy?: PrefetchStrategy, debug?: boolean);
|
|
104
|
+
/**
|
|
105
|
+
* Initialize the prefetch manager
|
|
106
|
+
* Loads configuration and sets up observers
|
|
107
|
+
*/
|
|
108
|
+
init(): Promise<void>;
|
|
109
|
+
/**
|
|
110
|
+
* Set the user segment for segment-based prefetch rules
|
|
111
|
+
* @param segment - The user's segment (e.g., 'premium', 'free', 'admin')
|
|
112
|
+
* @param fallbackToDefault - Use default rules if segment rules unavailable
|
|
113
|
+
*/
|
|
114
|
+
setSegment(segment: string | null, fallbackToDefault?: boolean): void;
|
|
115
|
+
/**
|
|
116
|
+
* Get the current segment
|
|
117
|
+
*/
|
|
118
|
+
getSegment(): string | null;
|
|
119
|
+
/**
|
|
120
|
+
* Prefetch routes based on current route
|
|
121
|
+
*/
|
|
122
|
+
prefetch(currentRoute: string): void;
|
|
123
|
+
/**
|
|
124
|
+
* Prefetch a specific target
|
|
125
|
+
*/
|
|
126
|
+
private prefetchTarget;
|
|
127
|
+
/**
|
|
128
|
+
* Hybrid strategy: prioritize based on probability
|
|
129
|
+
* FOR TESTING: Fetch all priorities to verify chunks are correct
|
|
130
|
+
*/
|
|
131
|
+
private prefetchHybrid;
|
|
132
|
+
/**
|
|
133
|
+
* Prefetch during idle time
|
|
134
|
+
*/
|
|
135
|
+
private prefetchOnIdle;
|
|
136
|
+
/**
|
|
137
|
+
* Resolve chunk path for the current environment
|
|
138
|
+
* In production: chunks are built with hashes (e.g., chunks/Privacy-D5qJZu-O.js or js/index-CJMMxcQV.js)
|
|
139
|
+
* In dev mode: need to resolve to the actual module or use a proxy
|
|
140
|
+
*/
|
|
141
|
+
private resolveChunkPath;
|
|
142
|
+
/**
|
|
143
|
+
* Inject prefetch link into DOM
|
|
144
|
+
*/
|
|
145
|
+
private injectPrefetchLink;
|
|
146
|
+
/**
|
|
147
|
+
* Check if prefetching should be performed based on network conditions
|
|
148
|
+
*/
|
|
149
|
+
private shouldPrefetch;
|
|
150
|
+
/**
|
|
151
|
+
* Initialize IntersectionObserver for 'visible' strategy
|
|
152
|
+
*/
|
|
153
|
+
private initIntersectionObserver;
|
|
154
|
+
/**
|
|
155
|
+
* Observe an element for visibility-based prefetching
|
|
156
|
+
*/
|
|
157
|
+
observeLink(element: HTMLElement, route: string): void;
|
|
158
|
+
/**
|
|
159
|
+
* Manually trigger prefetch for a specific route
|
|
160
|
+
* Useful for hover events
|
|
161
|
+
*/
|
|
162
|
+
prefetchRoute(route: string): void;
|
|
163
|
+
/**
|
|
164
|
+
* Get prefetch statistics
|
|
165
|
+
*/
|
|
166
|
+
getStats(): {
|
|
167
|
+
totalPrefetched: number;
|
|
168
|
+
prefetchedRoutes: string[];
|
|
169
|
+
configLoaded: boolean;
|
|
170
|
+
strategy: PrefetchStrategy;
|
|
171
|
+
};
|
|
172
|
+
/**
|
|
173
|
+
* Check if a route has been prefetched
|
|
174
|
+
*/
|
|
175
|
+
isPrefetched(route: string): boolean;
|
|
176
|
+
/**
|
|
177
|
+
* Clear all prefetch state
|
|
178
|
+
*/
|
|
179
|
+
clear(): void;
|
|
180
|
+
/**
|
|
181
|
+
* Get all prefetch link elements currently in the DOM
|
|
182
|
+
*/
|
|
183
|
+
getActivePrefetchLinks(): HTMLLinkElement[];
|
|
184
|
+
/**
|
|
185
|
+
* Log current state for debugging
|
|
186
|
+
*/
|
|
187
|
+
logDebugInfo(): void;
|
|
188
|
+
/**
|
|
189
|
+
* Log all prefetched pages and chunks (summary view)
|
|
190
|
+
*/
|
|
191
|
+
logPrefetchSummary(): void;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Debug Utilities for Smart Prefetch Plugin
|
|
196
|
+
* Helper functions to inspect and debug prefetch behavior
|
|
197
|
+
*/
|
|
198
|
+
/**
|
|
199
|
+
* Get all prefetch link elements from the DOM
|
|
200
|
+
*/
|
|
201
|
+
declare function getPrefetchLinks(): HTMLLinkElement[];
|
|
202
|
+
/**
|
|
203
|
+
* Get prefetch links added by our plugin (with data attributes)
|
|
204
|
+
*/
|
|
205
|
+
declare function getPluginPrefetchLinks(): HTMLLinkElement[];
|
|
206
|
+
/**
|
|
207
|
+
* Log all prefetch links in a formatted way
|
|
208
|
+
*/
|
|
209
|
+
declare function logPrefetchLinks(): void;
|
|
210
|
+
/**
|
|
211
|
+
* Monitor prefetch activity in real-time
|
|
212
|
+
*/
|
|
213
|
+
declare function monitorPrefetchActivity(): () => void;
|
|
214
|
+
/**
|
|
215
|
+
* Check if the smart prefetch plugin is properly configured
|
|
216
|
+
*/
|
|
217
|
+
declare function checkPluginConfiguration(): void;
|
|
218
|
+
/**
|
|
219
|
+
* Expose all debug utilities globally for console access
|
|
220
|
+
*/
|
|
221
|
+
declare function exposeDebugUtils(): void;
|
|
222
|
+
|
|
223
|
+
export { type PrefetchConfig, PrefetchManager, type PrefetchStrategy, type PrefetchTarget, checkPluginConfiguration, exposeDebugUtils, getPluginPrefetchLinks, getPrefetchLinks, logPrefetchLinks, monitorPrefetchActivity };
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
type PrefetchStrategy = 'auto' | 'hover' | 'visible' | 'idle' | 'hybrid';
|
|
2
|
+
interface ModelConfig {
|
|
3
|
+
/** Model type */
|
|
4
|
+
type: 'probability' | 'ml' | 'hybrid';
|
|
5
|
+
/** Minimum probability threshold (0.0 - 1.0, default: 0.3) */
|
|
6
|
+
threshold: number;
|
|
7
|
+
/** Maximum routes to prefetch per page (default: 3) */
|
|
8
|
+
maxPrefetch: number;
|
|
9
|
+
/** How often to update the model */
|
|
10
|
+
updateInterval?: 'build' | 'daily' | 'weekly';
|
|
11
|
+
}
|
|
12
|
+
interface DataSourceMetadata {
|
|
13
|
+
/** Provider name */
|
|
14
|
+
provider: 'bigquery' | 'markov-chain' | 'manual' | string;
|
|
15
|
+
/** Date range analyzed */
|
|
16
|
+
dateRange: string;
|
|
17
|
+
/** Total sessions analyzed */
|
|
18
|
+
totalSessions: number;
|
|
19
|
+
/** Total unique routes found */
|
|
20
|
+
totalRoutes?: number;
|
|
21
|
+
}
|
|
22
|
+
interface PrefetchTarget {
|
|
23
|
+
/** Target route to prefetch */
|
|
24
|
+
route: string;
|
|
25
|
+
/** Probability of transition (0.0 - 1.0) */
|
|
26
|
+
probability: number;
|
|
27
|
+
/** Number of observed transitions */
|
|
28
|
+
count: number;
|
|
29
|
+
/** Chunk file to prefetch (set by config generator) */
|
|
30
|
+
chunk?: string;
|
|
31
|
+
/** Dependency chunks to prefetch (extracted from Vite manifest imports) */
|
|
32
|
+
imports?: string[];
|
|
33
|
+
/** Priority level */
|
|
34
|
+
priority: 'high' | 'medium' | 'low';
|
|
35
|
+
/** Whether this is a manual rule */
|
|
36
|
+
manual?: boolean;
|
|
37
|
+
}
|
|
38
|
+
interface RouteMetadata {
|
|
39
|
+
/** Total transitions from this route */
|
|
40
|
+
totalTransitions: number;
|
|
41
|
+
/** Most common destination */
|
|
42
|
+
topDestination: string;
|
|
43
|
+
/** Average time spent on page (seconds) */
|
|
44
|
+
averageTimeOnPage?: number;
|
|
45
|
+
}
|
|
46
|
+
interface PrefetchConfig {
|
|
47
|
+
/** Schema version */
|
|
48
|
+
version: string;
|
|
49
|
+
/** Generation timestamp */
|
|
50
|
+
generatedAt: string;
|
|
51
|
+
/** Environment */
|
|
52
|
+
environment: string;
|
|
53
|
+
/** Data source info */
|
|
54
|
+
dataSource: DataSourceMetadata;
|
|
55
|
+
/** Model info */
|
|
56
|
+
model: {
|
|
57
|
+
type: ModelConfig['type'];
|
|
58
|
+
threshold: number;
|
|
59
|
+
maxPrefetch: number;
|
|
60
|
+
accuracy?: number;
|
|
61
|
+
};
|
|
62
|
+
/** Route predictions with chunk mappings */
|
|
63
|
+
routes: {
|
|
64
|
+
[sourceRoute: string]: {
|
|
65
|
+
/** Default/common prefetch rules (works for all users) */
|
|
66
|
+
prefetch: Array<PrefetchTarget & {
|
|
67
|
+
chunk: string;
|
|
68
|
+
}>;
|
|
69
|
+
/** Segment-specific rules (different per user segment) */
|
|
70
|
+
segments?: {
|
|
71
|
+
[segmentName: string]: Array<PrefetchTarget & {
|
|
72
|
+
chunk: string;
|
|
73
|
+
}>;
|
|
74
|
+
};
|
|
75
|
+
/** Metadata about this route */
|
|
76
|
+
metadata?: RouteMetadata;
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
/** Quick lookup: route -> chunk file */
|
|
80
|
+
chunks: {
|
|
81
|
+
[route: string]: string;
|
|
82
|
+
};
|
|
83
|
+
/** Available segments (for client-side selection) */
|
|
84
|
+
segmentInfo?: {
|
|
85
|
+
available: string[];
|
|
86
|
+
description?: string;
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Prefetch Manager (Runtime)
|
|
92
|
+
* Manages route prefetching in the browser
|
|
93
|
+
*/
|
|
94
|
+
|
|
95
|
+
declare class PrefetchManager {
|
|
96
|
+
private config;
|
|
97
|
+
private prefetched;
|
|
98
|
+
private strategy;
|
|
99
|
+
private observer;
|
|
100
|
+
private debug;
|
|
101
|
+
private currentSegment;
|
|
102
|
+
private fallbackToDefault;
|
|
103
|
+
constructor(strategy?: PrefetchStrategy, debug?: boolean);
|
|
104
|
+
/**
|
|
105
|
+
* Initialize the prefetch manager
|
|
106
|
+
* Loads configuration and sets up observers
|
|
107
|
+
*/
|
|
108
|
+
init(): Promise<void>;
|
|
109
|
+
/**
|
|
110
|
+
* Set the user segment for segment-based prefetch rules
|
|
111
|
+
* @param segment - The user's segment (e.g., 'premium', 'free', 'admin')
|
|
112
|
+
* @param fallbackToDefault - Use default rules if segment rules unavailable
|
|
113
|
+
*/
|
|
114
|
+
setSegment(segment: string | null, fallbackToDefault?: boolean): void;
|
|
115
|
+
/**
|
|
116
|
+
* Get the current segment
|
|
117
|
+
*/
|
|
118
|
+
getSegment(): string | null;
|
|
119
|
+
/**
|
|
120
|
+
* Prefetch routes based on current route
|
|
121
|
+
*/
|
|
122
|
+
prefetch(currentRoute: string): void;
|
|
123
|
+
/**
|
|
124
|
+
* Prefetch a specific target
|
|
125
|
+
*/
|
|
126
|
+
private prefetchTarget;
|
|
127
|
+
/**
|
|
128
|
+
* Hybrid strategy: prioritize based on probability
|
|
129
|
+
* FOR TESTING: Fetch all priorities to verify chunks are correct
|
|
130
|
+
*/
|
|
131
|
+
private prefetchHybrid;
|
|
132
|
+
/**
|
|
133
|
+
* Prefetch during idle time
|
|
134
|
+
*/
|
|
135
|
+
private prefetchOnIdle;
|
|
136
|
+
/**
|
|
137
|
+
* Resolve chunk path for the current environment
|
|
138
|
+
* In production: chunks are built with hashes (e.g., chunks/Privacy-D5qJZu-O.js or js/index-CJMMxcQV.js)
|
|
139
|
+
* In dev mode: need to resolve to the actual module or use a proxy
|
|
140
|
+
*/
|
|
141
|
+
private resolveChunkPath;
|
|
142
|
+
/**
|
|
143
|
+
* Inject prefetch link into DOM
|
|
144
|
+
*/
|
|
145
|
+
private injectPrefetchLink;
|
|
146
|
+
/**
|
|
147
|
+
* Check if prefetching should be performed based on network conditions
|
|
148
|
+
*/
|
|
149
|
+
private shouldPrefetch;
|
|
150
|
+
/**
|
|
151
|
+
* Initialize IntersectionObserver for 'visible' strategy
|
|
152
|
+
*/
|
|
153
|
+
private initIntersectionObserver;
|
|
154
|
+
/**
|
|
155
|
+
* Observe an element for visibility-based prefetching
|
|
156
|
+
*/
|
|
157
|
+
observeLink(element: HTMLElement, route: string): void;
|
|
158
|
+
/**
|
|
159
|
+
* Manually trigger prefetch for a specific route
|
|
160
|
+
* Useful for hover events
|
|
161
|
+
*/
|
|
162
|
+
prefetchRoute(route: string): void;
|
|
163
|
+
/**
|
|
164
|
+
* Get prefetch statistics
|
|
165
|
+
*/
|
|
166
|
+
getStats(): {
|
|
167
|
+
totalPrefetched: number;
|
|
168
|
+
prefetchedRoutes: string[];
|
|
169
|
+
configLoaded: boolean;
|
|
170
|
+
strategy: PrefetchStrategy;
|
|
171
|
+
};
|
|
172
|
+
/**
|
|
173
|
+
* Check if a route has been prefetched
|
|
174
|
+
*/
|
|
175
|
+
isPrefetched(route: string): boolean;
|
|
176
|
+
/**
|
|
177
|
+
* Clear all prefetch state
|
|
178
|
+
*/
|
|
179
|
+
clear(): void;
|
|
180
|
+
/**
|
|
181
|
+
* Get all prefetch link elements currently in the DOM
|
|
182
|
+
*/
|
|
183
|
+
getActivePrefetchLinks(): HTMLLinkElement[];
|
|
184
|
+
/**
|
|
185
|
+
* Log current state for debugging
|
|
186
|
+
*/
|
|
187
|
+
logDebugInfo(): void;
|
|
188
|
+
/**
|
|
189
|
+
* Log all prefetched pages and chunks (summary view)
|
|
190
|
+
*/
|
|
191
|
+
logPrefetchSummary(): void;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Debug Utilities for Smart Prefetch Plugin
|
|
196
|
+
* Helper functions to inspect and debug prefetch behavior
|
|
197
|
+
*/
|
|
198
|
+
/**
|
|
199
|
+
* Get all prefetch link elements from the DOM
|
|
200
|
+
*/
|
|
201
|
+
declare function getPrefetchLinks(): HTMLLinkElement[];
|
|
202
|
+
/**
|
|
203
|
+
* Get prefetch links added by our plugin (with data attributes)
|
|
204
|
+
*/
|
|
205
|
+
declare function getPluginPrefetchLinks(): HTMLLinkElement[];
|
|
206
|
+
/**
|
|
207
|
+
* Log all prefetch links in a formatted way
|
|
208
|
+
*/
|
|
209
|
+
declare function logPrefetchLinks(): void;
|
|
210
|
+
/**
|
|
211
|
+
* Monitor prefetch activity in real-time
|
|
212
|
+
*/
|
|
213
|
+
declare function monitorPrefetchActivity(): () => void;
|
|
214
|
+
/**
|
|
215
|
+
* Check if the smart prefetch plugin is properly configured
|
|
216
|
+
*/
|
|
217
|
+
declare function checkPluginConfiguration(): void;
|
|
218
|
+
/**
|
|
219
|
+
* Expose all debug utilities globally for console access
|
|
220
|
+
*/
|
|
221
|
+
declare function exposeDebugUtils(): void;
|
|
222
|
+
|
|
223
|
+
export { type PrefetchConfig, PrefetchManager, type PrefetchStrategy, type PrefetchTarget, checkPluginConfiguration, exposeDebugUtils, getPluginPrefetchLinks, getPrefetchLinks, logPrefetchLinks, monitorPrefetchActivity };
|