v-proximity-prefetch
Version:
Vue plugin that prefetches routes when the mouse approaches links for faster navigation
70 lines (68 loc) • 2.21 kB
TypeScript
import { Plugin } from 'vite';
/**
* Configuration options for the Vue Proximity Prefetch plugin
*/
export interface VueProximityPrefetchOptions {
/**
* Distance threshold in pixels that triggers prefetching when the cursor
* approaches a link element
* @default 200
*/
threshold?: number;
/**
* Interval for periodic prediction checks (in milliseconds)
* When set to 0, checks are triggered by mouse movements
* @default 0
*/
predictionInterval?: number;
/**
* Maximum number of routes to prefetch simultaneously
* Limits resource usage while still enhancing perceived performance
* @default 3
*/
maxPrefetch?: number;
/**
* Enable debug logging in the console
* Useful for development and troubleshooting
* @default false
*/
debug?: boolean;
/**
* Enable automatic prefetching without needing to add the Vue component
* When true, a global script is injected that handles prefetching for all routes
* @default false
*/
automaticPrefetch?: boolean;
/**
* Enable mobile support for touch devices
* When true, touch events and viewport-based prefetching are enabled
* @default true
*/
mobileSupport?: boolean;
/**
* Viewport margin (in pixels) for prefetching on mobile
* Links that are within this distance from the viewport will be prefetched
* @default 300
*/
viewportMargin?: number;
/**
* Enable prefetching of all links on the page at once
* When true, all internal links will be prefetched after page load
* @default false
*/
prefetchAllLinks?: boolean;
/**
* Delay (in milliseconds) before starting to prefetch all links
* Only used when prefetchAllLinks is true
* @default 1500
*/
prefetchAllLinksDelay?: number;
}
/**
* Creates a Vite plugin that enhances Vue Router with proximity-based prefetching
*
* @param options - Configuration options for the prefetching behavior
* @returns Vite plugin instance
*/
export declare function viteProximityPrefetch(options?: VueProximityPrefetchOptions): Plugin;
export default viteProximityPrefetch;