PageSourceSearch

https://www.stiga.com/static/version1790224918/frontend/Stiga/eCommerce/default/js/stiga/instant-prefetch.js

js stiga.com collected 2026-09-24 09:36:58 UTC 2,776 bytes, 82 lines download raw bytes

1/**
2 * Prefetch on hover/touch dei link interni.
3 *
4 * Ispirato a instant.page (MIT - https://instant.page/).
5 * Implementazione minimale senza dipendenze, adattata al contesto Stiga:
6 *  - evita prefetch di /checkout, /customer, /cart, /wishlist
7 *  - disabilitato su Save-Data e connessioni 2G
8 *  - escludibile via attributo data-no-instant sui link
9 */
10(function() {
11    'use strict';
12
13    if (!('IntersectionObserver' in window)) {
14        return;
15    }
16
17    var conn = navigator.connection;
18    if (conn && (conn.saveData || /2g/.test(conn.effectiveType || ''))) {
19        return;
20    }
21
22    var prefetches = new Set();
23    var HOVER_DELAY = 65;
24    var hoverTimer = null;
25
26    var EXCLUDED_PATH = /\/(checkout|customer|cart|wishlist|paypal|adyen|amasty_xnotif)(\/|$)/i;
27    var VOLATILE_PARAM = /\b(form_key|uenc|SID|isAjax|fromcart)=/i;
28
29    function isEligible(link) {
30        if (!link || !link.href) return false;
31        if (prefetches.has(link.href)) return false;
32        if (link.protocol !== 'http:' && link.protocol !== 'https:') return false;
33        if (link.origin !== location.origin) return false;
34        if (link.hasAttribute('data-no-instant')) return false;
35        if (link.getAttribute('target') === '_blank') return false;
36        if (link.pathname && EXCLUDED_PATH.test(link.pathname)) return false;
37        if (link.search && VOLATILE_PARAM.test(link.search)) return false;
38        if (link.href.indexOf('#') === 0) return false;
39        return true;
40    }
41
42    function prefetch(link) {
43        if (!isEligible(link)) return;
44        var url = link.href;
45        prefetches.add(url);
46        var l = document.createElement('link');
47        l.rel = 'prefetch';
48        l.href = url;
49        l.as = 'document';
50        document.head.appendChild(l);
51    }
52
53    function cancelHover() {
54        if (hoverTimer) {
55            clearTimeout(hoverTimer);
56            hoverTimer = null;
57        }
58    }
59
60    document.addEventListener('mouseover', function(e) {
61        var link = e.target.closest && e.target.closest('a');
62        if (!link || !isEligible(link)) return;
63
64        cancelHover();
65        hoverTimer = setTimeout(function() {
66            prefetch(link);
67            hoverTimer = null;
68        }, HOVER_DELAY);
69
70        link.addEventListener('mouseout', cancelHover, { once: true, capture: true });
71    }, { capture: true, passive: true });
72
73    document.addEventListener('mousedown', function(e) {
74        var link = e.target.closest && e.target.closest('a');
75        if (link) prefetch(link);
76    }, { capture: true, passive: true });
77
78    document.addEventListener('touchstart', function(e) {
79        var link = e.target.closest && e.target.closest('a');
80        if (link) prefetch(link);
81    }, { capture: true, passive: true });
82})();

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.