Instant Links, Hover/Touch Prefetch & WooCommerce Safety
Deliver near-0ms page transitions with 100ms hover/touch prefetching, 3-request rate throttling, CSP-aware script delivery, and automatic cart/checkout/logout exclusions.
- Prefetches same-origin public HTML links when an anonymous visitor hovers (
onHoverDelay = 100 ms) or starts touching a link on mobile, capped atrateThrottle = 3concurrent prefetches (InstantLinks.php). - Automatically disables itself for logged-in users, non-GET requests, plain (
?p=123) permalinks, and sites requiring pre-selection cookies (CookieIntegrations::required()). - Merges all private commerce, wishlist, account, logout, affiliate, and binary file exclusions automatically (
PrivateCommerceRoutes::wooPaths(), EDD pages, YITH Wishlist,excludedSegments, and48non-HTML file extensions). - Inspects active
Content-Security-Policyheaders viaCspPolicy.php(InstantLinks::finalize()), falling back from inline#kadicache-instant-linksto externaldeferinstant-links.jsautomatically when inline scripts are restricted.
How Browser-Side Link Prefetching Makes Navigation Feel Like an Instant SPA#
Even when Early PHP Drop-In Delivery serves HTML in 14 milliseconds on your server, a visitor on a mobile cellular network still experiences 80 ms to 220 ms of physical radio round-trip latency between tapping a product card and receiving the response bytes.
Human interaction research shows a reliable 120 ms to 300 ms gap between the moment a desktop user’s cursor settles over a link (or a mobile user’s finger touches touchstart) and the moment the click navigation commits. Instant Links (InstantLinks.php) uses that exact window to prefetch the destination HTML document into browser memory before the click finishes—so when the click fires, the next page paints in near 0 ms perceived wait time, making standard server-rendered WordPress feel as snappy as a client-side Single Page Application (SPA) without rewriting your theme!
Inside InstantLinks.php: Built-In Safety Rules That Prevent Accidental Side Effects#
Naive link-prefetch scripts are dangerous on WordPress and WooCommerce sites: prefetching ?add-to-cart=99 adds unwanted items to a shopper’s cart on hover; prefetching /customer-logout/ signs users out; prefetching /go/affiliate-partner/ inflates affiliate click counters; and prefetching a 60 MB .zip manual wastes mobile data!
InstantLinks.php eliminates every one of those hazards automatically through six layered safety filters:
Safety Layer in InstantLinks.php | Exact Built-In Protection | Why It Matters |
|---|---|---|
| 1. Anonymous & Pretty-Permalink Gate | Runs strictly for logged-out GET visits (!is_user_logged_in() & permalink_structure present) | Never prefetches admin links, draft previews, or logged-in account actions |
| 2. WooCommerce, EDD & Wishlist Auto-Merge | Merges PrivateCommerceRoutes::wooPaths(), EDD purchase/cart/history pages & YITH_WCWL wishlist URLs | Hovering Cart, Checkout, My Account, or Wishlist buttons never triggers private PHP requests |
3. Protected Path Segments (excludedSegments) | Blocks wp-login.php, wp-admin, wp-json, xmlrpc.php, wp-cron.php, customer-logout, logout, signout, out, go, refer, recommend, recommends | Protects auth endpoints, REST APIs, and /go/ or /out/ affiliate cloaking redirects! |
4. 48 Non-HTML File Extensions (fileExtensions) | Skips .pdf, .zip, .mp4, .mp3, .jpg, .png, .webp, .docx, .xlsx, .csv, .dmg, .exe, etc. | Never wastes visitor bandwidth prefetching downloadable documents, media, or archives |
| 5. Global & Per-Page Exclusions Sync | Automatically inherits excluded_paths, instant_links_exclusions, and Gutenberg never_cache (PostSettings::hintPaths()) | Exclude a route once in Cache or Gutenberg and Instant Links respects it automatically |
| 6. Hover Debounce & Rate Throttle | onHoverDelay: 100 ms + rateThrottle: 3 max concurrent prefetches | Sweeping a mouse rapidly across a 40-link mega-menu never floods your server |
Automatic Content-Security-Policy (CSP) Adaptation & Delay-JS Independence#
Two subtle engineering touches in InstantLinks.php make it resilient across enterprise security setups and aggressive script optimization:
- Immune to Delay JS & Minify Collisions (
InstantLinks::printScript()): KadiCache tags#kadicache-instant-linkswithdata-kadicache-no-delay,data-kadicache-no-defer,data-no-minify, anddata-kadicache-independentso even when Delay Until Interaction (Delay JS Guide) is active, link prefetching works immediately on first hover. - Smart
CspPolicyInline-to-External Fallback (InstantLinks::finalize()): Before sending HTML,InstantLinks::finalize()checks activeContent-Security-Policyheaders and<meta http-equiv="Content-Security-Policy">tags viaCspPolicy.php. If inline<script>execution is permitted (or matched by nonce/hash), it keeps the zero-request inline snippet; if strictscript-src 'self'blocks inline scripts, it automatically rewrites#kadicache-instant-linksto<script src=".../instant-links.js" defer>so zero CSP console errors ever fire!
<!-- Printed near </body> for anonymous guests only -->
<script id="kadicache-instant-links"
data-kadicache-links='{"excludedPaths":["/cart*","/checkout*","/my-account*"],"excludedSegments":["wp-login.php","wp-admin","wp-json","customer-logout","logout","signout","out","go","refer","recommend","recommends"],"onHoverDelay":100,"rateThrottle":3}'
data-kadicache-no-delay
data-kadicache-independent>/* minified instant-links runtime */</script>Adding Custom Instant Links Exclusions#
If your site uses a custom affiliate redirect prefix (such as /partner/* or /deal/*) or a dynamic state-changing GET link outside standard /out/ and /go/ conventions, open WP Admin -> KadiCache -> Preload, expand Instant Links Exclusions (instant_links_exclusions), and add /partner/* (one path or prefix wildcard per line).
- Respecting WooCommerce Dynamic Stock & Flash-Sale Pages: If you run a limited-drop flash sale page (
/limited-drop/) where inventory sells out every few seconds, either mark that page Never cache this page in Gutenberg or add/limited-drop/*to Instant Links Exclusions so browsers fetch live stock state at click time. - Zero Extra Network Weight (
< 1.8 KBMinified):InstantLinks.phpcaches its minified JavaScript payload in static memory (self::$minifiedCache), adding less than1.8 KB(under900 bytesgzipped) to guest HTML responses while keeping main-thread parsing cost under1 millisecondon mobile phones. - Skips
target="_blank",download& In-Page#hashAnchors Automatically: External tabs,mailto:/tel:links, HTML5downloadattributes, and same-page Table of Contents#anchorjumps are ignored natively so browser memory is reserved strictly for real internal page transitions.
Coordinating Instant Links With WooCommerce, Analytics & Edge CDNs#
- Zero False Pageviews in Google Analytics 4 (
GA4) & Plausible: Modern analytics scripts (gtag.js, Plausible, Fathom, Matomo, and KadiCache’s own Cookieless RUM) fire pageview beacons when a document becomes visible/activated, not during background HTML link prefetching—so enabling Instant Links never inflates your bounce rate or pageview counts. - Synergy With Cloudflare & Browser Revalidation: When a visitor hovers over a product card for
100 ms, the prefetch request warms both any upstream CDN edge PoP (Cloudflare, CDN & Varnish) and the browser’s in-memory prefetch cache—delivering instant visual transitions across desktop mice and mobile touchscreens alike.
Frequently Asked Operational Questions
Can Instant Links accidentally add items to a WooCommerce cart or log a customer out on hover?
Will hovering over /go/ or /out/ affiliate links trigger false affiliate clicks?
Does Instant Links work on Safari and Firefox as well as Chrome and Edge?
Will Instant Links overload my server if a user waves their mouse across a mega-menu?
Does Instant Links respect Data-Saver mode and strict Content-Security-Policy headers?
Creator of KadiCache’s Early PHP Drop-In, 7-Driver Object Cache Engine, Cloud Remove Unused CSS, and Zero-CLS Lazy Render pipeline.