@prefetchru/prefetch 1.1.0 → 1.1.2

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 CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [![npm](https://img.shields.io/npm/v/@prefetchru/prefetch?color=0969da)](https://www.npmjs.com/package/@prefetchru/prefetch)
4
4
  [![downloads](https://img.shields.io/npm/dm/@prefetchru/prefetch?color=0969da)](https://www.npmjs.com/package/@prefetchru/prefetch)
5
- [![size](https://img.shields.io/bundlephobia/minzip/@prefetchru/prefetch?color=0969da&label=gzip)](https://bundlephobia.com/package/@prefetchru/prefetch)
5
+ [![size](https://img.shields.io/badge/gzip-~4KB-0969da)](https://prefetch.ru)
6
6
  [![license](https://img.shields.io/npm/l/@prefetchru/prefetch?color=0969da)](LICENSE)
7
7
  [![release](https://img.shields.io/github/v/release/prefetch-ru/prefetch?color=0969da)](https://github.com/prefetch-ru/prefetch/releases)
8
8
  [![updated](https://img.shields.io/github/last-commit/prefetch-ru/prefetch?color=0969da&label=updated)](https://github.com/prefetch-ru/prefetch/commits)
@@ -27,7 +27,7 @@ Prefetch pages 65ms before user clicks. Pre-loads links on hover with smart fall
27
27
  - Специальная поддержка 1С-Битрикс и Tilda
28
28
  - Отключается на медленных соединениях (2G/3G) и режиме экономии трафика
29
29
  - Не влияет на работу аналитики (Яндекс.Метрика, Google Analytics)
30
- - ~3KB gzip, без зависимостей
30
+ - ~4KB gzip, без зависимостей
31
31
 
32
32
  ---
33
33
 
@@ -106,7 +106,7 @@ ESM версия автоматически определяет `nonce` чер
106
106
  | `data-prefetch-specrules-fallback` | — | Включить fallback при Speculation Rules |
107
107
  | `data-prefetch-whitelist` | — | Режим белого списка (только с `data-prefetch`) |
108
108
  | `data-prefetch-allow-query-string` | — | Разрешить ссылки с query-параметрами |
109
- | `data-prefetch-allow-external-links` | — | Разрешить внешние домены (только Chromium) |
109
+ | `data-prefetch-allow-external-links` | — | Разрешить внешние домены |
110
110
  | `data-prefetch-observe-dom` | — | Отслеживать новые ссылки (для SPA) |
111
111
  | `data-prefetch-nonce` | `"abc123"` | Nonce для Content Security Policy |
112
112
  | `data-prefetch-prerender-all` | — | Разрешить prerender для всех ссылок |
@@ -139,7 +139,7 @@ ESM версия автоматически определяет `nonce` чер
139
139
  // (window.Prefetch также доступен, если не занят другой библиотекой)
140
140
 
141
141
  // Версия библиотеки
142
- console.log(PrefetchRu.version) // "1.1.0"
142
+ console.log(PrefetchRu.version) // "1.1.2"
143
143
 
144
144
  // Программная предзагрузка URL
145
145
  // ВАЖНО: URL проходит те же проверки, что и автоматические ссылки
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * prefetch.ru v1.1.0 (ESM) - Мгновенная загрузка страниц
2
+ * prefetch.ru v1.1.2 (ESM) - Мгновенная загрузка страниц
3
3
  * © 2026 Сергей Макаров | MIT License
4
4
  * https://prefetch.ru | https://github.com/prefetch-ru
5
5
  */
6
- var e="undefined"!=typeof window&&window.PrefetchRu&&window.PrefetchRu.__prefetchRu?window.PrefetchRu:"undefined"!=typeof window&&window.Prefetch&&window.Prefetch.__prefetchRu?window.Prefetch:function(e){var t=e&&e.getNonce;if(!(!e||e.isBrowser)||"undefined"==typeof window||"undefined"==typeof document)return{__prefetchRu:!0,version:"1.1.0",preload:function(){},destroy:function(){},refresh:function(){}};var n=new Set,r=new WeakMap,i=!1,o=0,a=[],c=new Set,s={prefetch:[],prerender:[],crossOrigin:[]},u=0,l="",d=0,f=0,h=null,p=!1,m=!1,v=null,g=null,w=!1,y=null,b=null,E=!1,L=65,x=80,T=50,k=!1,O=!1,P=!1,A=!1,S="none",N=!1,C=!1,q=!1,I=!1,R=!1,M=/(^|\/)(login|logout|auth|register|cart|basket|add|delete|remove)(\/|$|\.)/i,_=/\.(pdf|doc|docx|xls|xlsx|zip|rar|exe)($|\?)/i;function D(){if(!i){var e=document.body;if(e){l=location.origin+location.pathname+location.search,g=void 0!==window.BX?"bitrix":void 0!==window.B24||void 0!==window.BX24?"bitrix24":document.querySelector(".t-records")||void 0!==window.Tilda?"tilda":null;var t=e.dataset;if(k="prefetchAllowQueryString"in t||"instantAllowQueryString"in t,O="prefetchAllowExternalLinks"in t||"instantAllowExternalLinks"in t,P="prefetchWhitelist"in t||"instantWhitelist"in t,t.prefetchNonce&&(b=t.prefetchNonce),!b&&t.instantNonce&&(b=t.instantNonce),!m&&("prefetchSpecrules"in t||"instantSpecrules"in t)&&HTMLScriptElement.supports&&HTMLScriptElement.supports("speculationrules")){var n=t.prefetchSpecrules||t.instantSpecrules;"prerender"===n?(S="prerender",A=!0):"no"!==n&&(S="prefetch",A=!0)}N="prefetchSpecrulesFallback"in t||"instantSpecrulesFallback"in t,C="prefetchPrerenderAll"in t||"instantPrerenderAll"in t;var r=t.prefetchIntensity||t.instantIntensity;if("mousedown"===r)q=!0;else if("viewport"===r||"viewport-all"===r)("viewport-all"===r||p&&U())&&(I=!0);else if(r){var o=parseInt(r,10);!isNaN(o)&&o>=0&&(L=o)}p&&(x=Math.max(60,Math.min(L||0,150))),(R="prefetchObserveDom"in t||"instantObserveDom"in t)||"bitrix"!==g&&"tilda"!==g||(R=!0),window.addEventListener("popstate",W),window.addEventListener("hashchange",W),window.addEventListener("pageshow",B),"tilda"===g&&L<100&&(L=100);var a={capture:!0,passive:!0};if(document.addEventListener("touchstart",K,a),q?document.addEventListener("mousedown",G,a):document.addEventListener("mouseover",j,a),I&&"undefined"==typeof IntersectionObserver&&(I=!1),I)(window.requestIdleCallback||function(e){setTimeout(e,1)})(ee,{timeout:1500});R&&I&&"undefined"!=typeof MutationObserver&&function(){if(i)return;if(ne)return;(ne=new MutationObserver(function(e){var t=!1;e:for(var n=0;n<e.length;n++)for(var r=e[n].addedNodes,i=0;i<r.length;i++){var o=r[i];if(1===o.nodeType&&("A"===o.tagName||o.querySelector&&o.querySelector("a"))){t=!0;break e}}t&&Z&&(clearTimeout(re),re=setTimeout(te,100))})).observe(document.body,{childList:!0,subtree:!0})}()}}}function U(){return!w&&("slow-2g"!==y&&"2g"!==y&&"3g"!==y)}function W(){l=location.origin+location.pathname+location.search}function B(e){e&&e.persisted&&W()}function z(e){return e?(e.nodeType&&1!==e.nodeType&&(e=e.parentElement),e&&"function"==typeof e.closest?e.closest("a"):null):null}function K(e){if(!(i||e&&!1===e.isTrusted)){d=Date.now();var t=z(e.target);if(H(t)){f&&(clearTimeout(f),f=0),h&&(document.removeEventListener("touchmove",h,!0),document.removeEventListener("scroll",h,!0),h=null);var n=!1;h=function(){n=!0,f&&(clearTimeout(f),f=0),document.removeEventListener("touchmove",h,!0),document.removeEventListener("scroll",h,!0),h=null},document.addEventListener("touchmove",h,{capture:!0,passive:!0,once:!0}),document.addEventListener("scroll",h,{capture:!0,passive:!0,once:!0}),f=setTimeout(function(){h&&(document.removeEventListener("touchmove",h,!0),document.removeEventListener("scroll",h,!0),h=null),f=0,n||Q(t.href,t)},x)}}}function j(e){if(!i&&!(e&&!1===e.isTrusted||d&&Date.now()-d<2500)){var t=z(e.target);if(t&&!r.has(t)&&H(t)){t.addEventListener("mouseleave",F,{passive:!0,once:!0});var n=setTimeout(function(){Q(t.href,t),r.delete(t)},L);r.set(t,n)}}}function F(e){var t=e.currentTarget;if(t){var n=r.get(t);n&&(clearTimeout(n),r.delete(t))}}function G(e){if(!i&&!(e&&!1===e.isTrusted||"number"==typeof e.button&&(1===e.button||2===e.button)||e.metaKey||e.ctrlKey||e.shiftKey||e.altKey||d&&Date.now()-d<2500)){var t=z(e.target);H(t)&&Q(t.href,t)}}function H(e){if(!e)return!1;var t=e.getAttribute("href");if(null===t||""===t.trim())return!1;if(!e.href)return!1;if(e.target&&"_self"!==e.target)return!1;if(e.hasAttribute("download"))return!1;if("noPrefetch"in e.dataset||"prefetchNo"in e.dataset)return!1;if(P&&!("prefetch"in e.dataset)&&!("instant"in e.dataset))return!1;if("http:"!==e.protocol&&"https:"!==e.protocol)return!1;if("http:"===e.protocol&&"https:"===location.protocol)return!1;if(e.origin!==location.origin){if(!O&&!("prefetch"in e.dataset)&&!("instant"in e.dataset))return!1;if(!v)return!1}if(e.search&&!k&&!("prefetch"in e.dataset)&&!("instant"in e.dataset))return!1;if(e.hash&&e.pathname+e.search===location.pathname+location.search)return!1;var r=e.origin+e.pathname+e.search;return r!==l&&(!n.has(r)&&(!!function(e){var t=e.href,n=e.pathname||"",r=e.hash||"";if("bitrix"===g||"bitrix24"===g){if(-1!==t.indexOf("/bitrix/")||-1!==t.indexOf("sessid="))return!1;if(e.classList.contains("bx-ajax"))return!1}if("tilda"===g&&(-1!==r.indexOf("#popup:")||-1!==r.indexOf("#rec")))return!1;return!M.test(n)&&!_.test(n)}(e)&&!!function(e){var t=e.className||"",n=e.hostname||"";return-1===t.indexOf("ym-")&&("mc.yandex.ru"!==n&&"metrika.yandex.ru"!==n&&(-1===t.indexOf("ga-")&&-1===t.indexOf("gtm-")&&("google-analytics.com"!==n&&!n.endsWith(".google-analytics.com")&&("googletagmanager.com"!==n&&!n.endsWith(".googletagmanager.com")&&(-1===t.indexOf("piwik")&&-1===t.indexOf("matomo")&&("matomo.org"!==n&&!n.endsWith(".matomo.org")&&"piwik.org"!==n&&!n.endsWith(".piwik.org")))))))}(e)))}function Q(e,t){if(!i&&U()){var r=function(e){try{var t=new URL(e,location.href),n=t.origin+t.pathname+t.search;return t.hash="",{requestUrl:t.href,key:n}}catch(t){return{requestUrl:e,key:e}}}(e),c=r.requestUrl,s=r.key;if(!n.has(s)){n.size>=T&&n.delete(n.values().next().value),n.add(s);var u=function(e){return A&&"none"!==S?"prerender"!==S?S:C||P||e&&e.dataset&&("prefetchPrerender"in e.dataset||"instantPrerender"in e.dataset)?"prerender":"prefetch":"none"}(t);if(o>=4)return a.length>=50?void n.delete(s):void a.push({url:c,key:s,mode:u});X(c,s,u)}}}function X(e,t,n){if("none"===n)m||!E?Y(e,t):V(e,t);else{var r=!1;try{!function(e,t){var n=!1;try{n=new URL(e,location.href).origin!==location.origin}catch(e){}n&&"prerender"===t&&(t="prefetch");n?s.crossOrigin.push(e):"prerender"===t?s.prerender.push(e):s.prefetch.push(e);if(!u){var r=window.requestIdleCallback||function(e){setTimeout(e,1)};u=r(J,{timeout:50})}}(e,n),r=!0}catch(e){}!N&&r||(m||!E?Y(e,t):V(e,t))}}function $(){for(;a.length>0&&o<4;){var e=a.shift();X(e.url,e.key,e.mode)}}function J(){if(u=0,!i){var e=document.head;if(e){var t={};if(s.prefetch.length>0&&(t.prefetch=t.prefetch||[],t.prefetch.push({source:"list",urls:s.prefetch.slice()}),s.prefetch.length=0),s.prerender.length>0&&(t.prerender=t.prerender||[],t.prerender.push({source:"list",urls:s.prerender.slice()}),s.prerender.length=0),s.crossOrigin.length>0&&(t.prefetch=t.prefetch||[],t.prefetch.push({source:"list",urls:s.crossOrigin.slice(),referrer_policy:"no-referrer",requires:["anonymous-client-ip-when-cross-origin"]}),s.crossOrigin.length=0),t.prefetch||t.prerender){var n=document.createElement("script");n.type="speculationrules",b&&(n.nonce=b),n.textContent=JSON.stringify(t),e.appendChild(n),e.removeChild(n)}}}}function V(e,t){var r=document.head;if(r){o++;var i=document.createElement("link");i.rel="prefetch",i.href=e,i.as="document";try{i.fetchPriority="low"}catch(e){}try{new URL(e,location.href).origin!==location.origin&&(i.referrerPolicy="no-referrer",i.crossOrigin="anonymous")}catch(e){}var a=setTimeout(function(){a=0,n.delete(t),c()},3e4);i.onload=c,i.onerror=function(){n.delete(t),c()},r.appendChild(i)}else n.delete(t);function c(){a&&(clearTimeout(a),a=0),i.onload=i.onerror=null,i.parentNode&&i.parentNode.removeChild(i),o--,$()}}function Y(e,t){if("function"==typeof fetch){o++;var r=!1,i=null,a=0;"undefined"!=typeof AbortController&&(i=new AbortController,c.add(i),a=setTimeout(function(){try{i.abort()}catch(e){}l(!1)},5e3));var s=!1;try{s=new URL(e,location.href).origin!==location.origin}catch(e){}var u={method:"GET",cache:"force-cache",credentials:s?"omit":"same-origin",headers:{Accept:"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"}};s||(u.headers.Purpose="prefetch"),s&&(u.referrerPolicy="no-referrer"),i&&(u.signal=i.signal);try{fetch(e,u).then(function(e){l(e&&(e.ok||304===e.status))}).catch(function(){l(!1)})}catch(e){l(!1)}}else n.delete(t);function l(e){r||(r=!0,a&&clearTimeout(a),i&&c.delete(i),e||n.delete(t),o--,$())}}!function(){if(t)try{b=t()}catch(e){}try{var e=document.createElement("link");e.relList&&"function"==typeof e.relList.supports&&(E=e.relList.supports("prefetch"))}catch(e){}var n=navigator.userAgent,r=navigator.userAgentData;if(r){m=!1;var i="Android"===r.platform;p=r.mobile||!1;for(var o=r.brands||[],a=0;a<o.length;a++){var c=o[a];if("Chromium"===c.brand||"Google Chrome"===c.brand){v=parseInt(c.version,10);break}}}else{m=/iPad|iPhone/.test(n)||"MacIntel"===navigator.platform&&navigator.maxTouchPoints>1;i=/Android/.test(n);p=(m||i)&&Math.min(screen.width,screen.height)<768;var s=n.match(/Chrome\/(\d+)/);s&&(v=parseInt(s[1],10))}p&&(T=20);var u=navigator.connection;u&&(y=u.effectiveType,w=u.saveData||!1),"loading"===document.readyState?document.addEventListener("DOMContentLoaded",D):D()}();var Z=null;function ee(){i||Z||(Z=new IntersectionObserver(function(e){e.forEach(function(e){e.isIntersecting&&(Z.unobserve(e.target),H(e.target)&&Q(e.target.href,e.target))})},{rootMargin:p?"100px":"200px"}),te())}function te(){Z&&document.querySelectorAll("a").forEach(function(e){H(e)&&Z.observe(e)})}var ne=null,re=null;return{__prefetchRu:!0,version:"1.1.0",preload:function(e){if(function(e){return!(!e||"string"!=typeof e||!(e=e.trim())||/^\/\//.test(e)||/^(javascript|data|vbscript|file):/i.test(e)||!(/^https?:\/\//i.test(e)||/^\//.test(e)||/^\./.test(e))&&/^[a-z][a-z0-9+.-]*:/i.test(e))}(e)){var t=document.createElement("a");t.setAttribute("href",e.trim()),H(t)&&Q(t.href,t)}},destroy:function(){i=!0,a.length=0,f&&(clearTimeout(f),f=0),h&&(document.removeEventListener("touchmove",h,!0),document.removeEventListener("scroll",h,!0),h=null),c.forEach(function(e){try{e.abort()}catch(e){}}),c.clear(),u&&((window.cancelIdleCallback||clearTimeout)(u),u=0),s.prefetch.length=s.prerender.length=s.crossOrigin.length=0;var e={capture:!0,passive:!0};document.removeEventListener("touchstart",K,e),document.removeEventListener("mouseover",j,e),document.removeEventListener("mousedown",G,e),window.removeEventListener("popstate",W),window.removeEventListener("hashchange",W),window.removeEventListener("pageshow",B),Z&&(Z.disconnect(),Z=null),ne&&(ne.disconnect(),ne=null)},refresh:W}}({isBrowser:"undefined"!=typeof window,getNonce:function(){var e=function(e){try{if(!e)return null;for(var t=document.getElementsByTagName("script"),n=0;n<t.length;n++){var r=t[n];if(r&&r.src&&r.src===e){var i=r.nonce||r.getAttribute("nonce")||null;if(i)return i;break}}}catch(e){}return null}(import.meta.url);if(e)return e;try{var t=document.currentScript;if(t&&t.nonce)return t.nonce}catch(e){}return null}});"undefined"!=typeof window&&(window.PrefetchRu=e,window.Prefetch||(window.Prefetch=e));export{e as Prefetch,e as default};
6
+ var e="undefined"!=typeof window&&window.PrefetchRu&&window.PrefetchRu.__prefetchRu?window.PrefetchRu:"undefined"!=typeof window&&window.Prefetch&&window.Prefetch.__prefetchRu?window.Prefetch:function(e){var t=e&&e.getNonce;if(!(!e||e.isBrowser)||"undefined"==typeof window||"undefined"==typeof document)return{__prefetchRu:!0,version:"1.1.2",preload:function(){},destroy:function(){},refresh:function(){}};var n=new Set,r=new WeakMap,o=!1,i=0,a=[],c=new Set,s={prefetch:[],prerender:[],crossOrigin:[]},u=0,l="",d=0,f=0,h=null,p=!1,m=!1,v=null,g=!1,w=null,y=null,b=!1,L=65,E=80,x=50,T=!1,k=!1,O=!1,P=!1,A="none",S=!1,N=!1,C=!1,q=!1,R=!1,I=/(^|\/)(login|logout|auth|register|cart|basket|add|delete|remove)(\/|$|\.)/i,M=/\.(pdf|doc|docx|xls|xlsx|zip|rar|exe)($|\?)/i;function _(){if(!o){var e=document.body;if(e){l=location.origin+location.pathname+location.search,v=void 0!==window.BX?"bitrix":void 0!==window.B24||void 0!==window.BX24?"bitrix24":document.querySelector(".t-records")||void 0!==window.Tilda?"tilda":null;var t=e.dataset;if(T="prefetchAllowQueryString"in t||"instantAllowQueryString"in t,k="prefetchAllowExternalLinks"in t||"instantAllowExternalLinks"in t,O="prefetchWhitelist"in t||"instantWhitelist"in t,t.prefetchNonce&&(y=t.prefetchNonce),!y&&t.instantNonce&&(y=t.instantNonce),!m&&("prefetchSpecrules"in t||"instantSpecrules"in t)&&HTMLScriptElement.supports&&HTMLScriptElement.supports("speculationrules")){var n=t.prefetchSpecrules||t.instantSpecrules;"prerender"===n?(A="prerender",P=!0):"no"!==n&&(A="prefetch",P=!0)}S="prefetchSpecrulesFallback"in t||"instantSpecrulesFallback"in t,N="prefetchPrerenderAll"in t||"instantPrerenderAll"in t;var r=t.prefetchIntensity||t.instantIntensity;if("mousedown"===r)C=!0;else if("viewport"===r||"viewport-all"===r)("viewport-all"===r||p&&D())&&(q=!0);else if(r){var i=parseInt(r,10);!isNaN(i)&&i>=0&&(L=i)}p&&(E=Math.max(60,Math.min(L||0,150))),(R="prefetchObserveDom"in t||"instantObserveDom"in t)||"bitrix"!==v&&"tilda"!==v||(R=!0),window.addEventListener("popstate",U),window.addEventListener("hashchange",U),window.addEventListener("pageshow",W),"tilda"===v&&L<100&&(L=100);var a={capture:!0,passive:!0};if(document.addEventListener("touchstart",z,a),C?document.addEventListener("mousedown",F,a):document.addEventListener("mouseover",K,a),q&&"undefined"==typeof IntersectionObserver&&(q=!1),q)(window.requestIdleCallback||function(e){setTimeout(e,1)})(Z,{timeout:1500});R&&q&&"undefined"!=typeof MutationObserver&&function(){if(o)return;if(te)return;(te=new MutationObserver(function(e){var t=!1;e:for(var n=0;n<e.length;n++)for(var r=e[n].addedNodes,o=0;o<r.length;o++){var i=r[o];if(1===i.nodeType&&("A"===i.tagName||i.querySelector&&i.querySelector("a"))){t=!0;break e}}t&&Y&&(clearTimeout(ne),ne=setTimeout(ee,100))})).observe(document.body,{childList:!0,subtree:!0})}()}}}function D(){return!g&&("slow-2g"!==w&&"2g"!==w&&"3g"!==w)}function U(){l=location.origin+location.pathname+location.search}function W(e){e&&e.persisted&&U()}function B(e){return e?(e.nodeType&&1!==e.nodeType&&(e=e.parentElement),e&&"function"==typeof e.closest?e.closest("a"):null):null}function z(e){if(!(o||e&&!1===e.isTrusted)){d=Date.now();var t=B(e.target);if(G(t)){f&&(clearTimeout(f),f=0),h&&(document.removeEventListener("touchmove",h,!0),document.removeEventListener("scroll",h,!0),h=null);var n=!1;h=function(){n=!0,f&&(clearTimeout(f),f=0),document.removeEventListener("touchmove",h,!0),document.removeEventListener("scroll",h,!0),h=null},document.addEventListener("touchmove",h,{capture:!0,passive:!0,once:!0}),document.addEventListener("scroll",h,{capture:!0,passive:!0,once:!0}),f=setTimeout(function(){h&&(document.removeEventListener("touchmove",h,!0),document.removeEventListener("scroll",h,!0),h=null),f=0,n||H(t.href,t)},E)}}}function K(e){if(!o&&!(e&&!1===e.isTrusted||d&&Date.now()-d<2500)){var t=B(e.target);if(t&&!r.has(t)&&G(t)){t.addEventListener("mouseleave",j,{passive:!0,once:!0});var n=setTimeout(function(){H(t.href,t),r.delete(t)},L);r.set(t,n)}}}function j(e){var t=e.currentTarget;if(t){var n=r.get(t);n&&(clearTimeout(n),r.delete(t))}}function F(e){if(!o&&!(e&&!1===e.isTrusted||"number"==typeof e.button&&(1===e.button||2===e.button)||e.metaKey||e.ctrlKey||e.shiftKey||e.altKey||d&&Date.now()-d<2500)){var t=B(e.target);G(t)&&H(t.href,t)}}function G(e){if(!e)return!1;var t=e.getAttribute("href");if(null===t||""===t.trim())return!1;if(!e.href)return!1;if(e.target&&"_self"!==e.target)return!1;if(e.hasAttribute("download"))return!1;if("noPrefetch"in e.dataset||"prefetchNo"in e.dataset)return!1;if(O&&!("prefetch"in e.dataset)&&!("instant"in e.dataset))return!1;if("http:"!==e.protocol&&"https:"!==e.protocol)return!1;if("http:"===e.protocol&&"https:"===location.protocol)return!1;if(e.origin!==location.origin&&!k&&!("prefetch"in e.dataset)&&!("instant"in e.dataset))return!1;if(e.search&&!T&&!("prefetch"in e.dataset)&&!("instant"in e.dataset))return!1;if(e.hash&&e.pathname+e.search===location.pathname+location.search)return!1;var r=e.origin+e.pathname+e.search;return r!==l&&(!n.has(r)&&(!!function(e){var t=e.href,n=e.pathname||"",r=e.hash||"";if("bitrix"===v||"bitrix24"===v){if(-1!==t.indexOf("/bitrix/")||-1!==t.indexOf("sessid="))return!1;if(e.classList.contains("bx-ajax"))return!1}if("tilda"===v&&(-1!==r.indexOf("#popup:")||-1!==r.indexOf("#rec")))return!1;return!I.test(n)&&!M.test(n)}(e)&&!!function(e){var t=e.className||"",n=e.hostname||"";return-1===t.indexOf("ym-")&&("mc.yandex.ru"!==n&&"metrika.yandex.ru"!==n&&(-1===t.indexOf("ga-")&&-1===t.indexOf("gtm-")&&("google-analytics.com"!==n&&!n.endsWith(".google-analytics.com")&&("googletagmanager.com"!==n&&!n.endsWith(".googletagmanager.com")&&(-1===t.indexOf("piwik")&&-1===t.indexOf("matomo")&&("matomo.org"!==n&&!n.endsWith(".matomo.org")&&"piwik.org"!==n&&!n.endsWith(".piwik.org")))))))}(e)))}function H(e,t){if(!o&&D()){var r=function(e){try{var t=new URL(e,location.href),n=t.origin+t.pathname+t.search;return t.hash="",{requestUrl:t.href,key:n}}catch(t){return{requestUrl:e,key:e}}}(e),c=r.requestUrl,s=r.key;if(!n.has(s)){n.size>=x&&n.delete(n.values().next().value),n.add(s);var u=function(e){return P&&"none"!==A?"prerender"!==A?A:N||O||e&&e.dataset&&("prefetchPrerender"in e.dataset||"instantPrerender"in e.dataset)?"prerender":"prefetch":"none"}(t);if(i>=4)return a.length>=50?void n.delete(s):void a.push({url:c,key:s,mode:u});Q(c,s,u)}}}function Q(e,t,n){var r=!1;try{r=new URL(e,location.href).origin!==location.origin}catch(e){}if("none"===n)m||!b||r?V(e,t):J(e,t);else{var o=!1;try{!function(e,t){var n=!1;try{n=new URL(e,location.href).origin!==location.origin}catch(e){}n&&"prerender"===t&&(t="prefetch");n?s.crossOrigin.push(e):"prerender"===t?s.prerender.push(e):s.prefetch.push(e);if(!u){var r=window.requestIdleCallback||function(e){setTimeout(e,1)};u=r($,{timeout:50})}}(e,n),o=!0}catch(e){}!S&&o||(m||!b||r?V(e,t):J(e,t))}}function X(){for(;a.length>0&&i<4;){var e=a.shift();Q(e.url,e.key,e.mode)}}function $(){if(u=0,!o){var e=document.head;if(e){var t={};if(s.prefetch.length>0&&(t.prefetch=t.prefetch||[],t.prefetch.push({source:"list",urls:s.prefetch.slice()}),s.prefetch.length=0),s.prerender.length>0&&(t.prerender=t.prerender||[],t.prerender.push({source:"list",urls:s.prerender.slice()}),s.prerender.length=0),s.crossOrigin.length>0&&(t.prefetch=t.prefetch||[],t.prefetch.push({source:"list",urls:s.crossOrigin.slice(),referrer_policy:"no-referrer",requires:["anonymous-client-ip-when-cross-origin"]}),s.crossOrigin.length=0),t.prefetch||t.prerender){var n=document.createElement("script");n.type="speculationrules",y&&(n.nonce=y),n.textContent=JSON.stringify(t),e.appendChild(n),e.removeChild(n)}}}}function J(e,t){var r=document.head;if(r){i++;var o=document.createElement("link");o.rel="prefetch",o.href=e,o.as="document";try{o.fetchPriority="low"}catch(e){}try{new URL(e,location.href).origin!==location.origin&&(o.referrerPolicy="no-referrer",o.crossOrigin="anonymous")}catch(e){}var a=setTimeout(function(){a=0,n.delete(t),c()},3e4);o.onload=c,o.onerror=function(){n.delete(t),c()},r.appendChild(o)}else n.delete(t);function c(){a&&(clearTimeout(a),a=0),o.onload=o.onerror=null,o.parentNode&&o.parentNode.removeChild(o),i--,X()}}function V(e,t){if("function"==typeof fetch){i++;var r=!1,o=null,a=0;"undefined"!=typeof AbortController&&(o=new AbortController,c.add(o),a=setTimeout(function(){try{o.abort()}catch(e){}l(!1)},5e3));var s=!1;try{s=new URL(e,location.href).origin!==location.origin}catch(e){}var u={method:"GET",cache:"force-cache",credentials:s?"omit":"same-origin",mode:s?"no-cors":"cors"};s||(u.headers={Accept:"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",Purpose:"prefetch"}),s&&(u.referrerPolicy="no-referrer"),o&&(u.signal=o.signal);try{fetch(e,u).then(function(e){l(e&&(e.ok||304===e.status||"opaque"===e.type))}).catch(function(){l(!1)})}catch(e){l(!1)}}else n.delete(t);function l(e){r||(r=!0,a&&clearTimeout(a),o&&c.delete(o),e||n.delete(t),i--,X())}}!function(){if(t)try{y=t()}catch(e){}try{var e=document.createElement("link");e.relList&&"function"==typeof e.relList.supports&&(b=e.relList.supports("prefetch"))}catch(e){}var n=navigator.userAgent,r=navigator.userAgentData;if(r){m=!1;var o="Android"===r.platform;p=r.mobile||!1;for(var i=r.brands||[],a=0;a<i.length;a++){var c=i[a];if("Chromium"===c.brand||"Google Chrome"===c.brand){parseInt(c.version,10);break}}}else{m=/iPad|iPhone/.test(n)||"MacIntel"===navigator.platform&&navigator.maxTouchPoints>1;o=/Android/.test(n);p=(m||o)&&Math.min(screen.width,screen.height)<768;var s=n.match(/Chrome\/(\d+)/);s&&parseInt(s[1],10)}p&&(x=20);var u=navigator.connection;u&&(w=u.effectiveType,g=u.saveData||!1),"loading"===document.readyState?document.addEventListener("DOMContentLoaded",_):_()}();var Y=null;function Z(){o||Y||(Y=new IntersectionObserver(function(e){e.forEach(function(e){e.isIntersecting&&(Y.unobserve(e.target),G(e.target)&&H(e.target.href,e.target))})},{rootMargin:p?"100px":"200px"}),ee())}function ee(){Y&&document.querySelectorAll("a").forEach(function(e){G(e)&&Y.observe(e)})}var te=null,ne=null;return{__prefetchRu:!0,version:"1.1.2",preload:function(e){if(function(e){return!(!e||"string"!=typeof e||!(e=e.trim())||/^\/\//.test(e)||/^(javascript|data|vbscript|file):/i.test(e)||!(/^https?:\/\//i.test(e)||/^\//.test(e)||/^\./.test(e))&&/^[a-z][a-z0-9+.-]*:/i.test(e))}(e)){var t=document.createElement("a");t.setAttribute("href",e.trim()),G(t)&&H(t.href,t)}},destroy:function(){o=!0,a.length=0,f&&(clearTimeout(f),f=0),h&&(document.removeEventListener("touchmove",h,!0),document.removeEventListener("scroll",h,!0),h=null),c.forEach(function(e){try{e.abort()}catch(e){}}),c.clear(),u&&((window.cancelIdleCallback||clearTimeout)(u),u=0),s.prefetch.length=s.prerender.length=s.crossOrigin.length=0;var e={capture:!0,passive:!0};document.removeEventListener("touchstart",z,e),document.removeEventListener("mouseover",K,e),document.removeEventListener("mousedown",F,e),window.removeEventListener("popstate",U),window.removeEventListener("hashchange",U),window.removeEventListener("pageshow",W),Y&&(Y.disconnect(),Y=null),te&&(te.disconnect(),te=null)},refresh:U}}({isBrowser:"undefined"!=typeof window,getNonce:function(){var e=function(e){try{if(!e)return null;for(var t=document.getElementsByTagName("script"),n=0;n<t.length;n++){var r=t[n];if(r&&r.src&&r.src===e){var o=r.nonce||r.getAttribute("nonce")||null;if(o)return o;break}}}catch(e){}return null}(import.meta.url);if(e)return e;try{var t=document.currentScript;if(t&&t.nonce)return t.nonce}catch(e){}return null}});"undefined"!=typeof window&&(window.PrefetchRu=e,window.Prefetch||(window.Prefetch=e));export{e as Prefetch,e as default};
@@ -1,6 +1,6 @@
1
1
  /*!
2
- * prefetch.ru v1.1.0 - Мгновенная загрузка страниц
2
+ * prefetch.ru v1.1.2 - Мгновенная загрузка страниц
3
3
  * © 2026 Сергей Макаров | MIT License
4
4
  * https://prefetch.ru | https://github.com/prefetch-ru
5
5
  */
6
- !function(){"use strict";if(!(window.PrefetchRu&&window.PrefetchRu.__prefetchRu||window.Prefetch&&window.Prefetch.__prefetchRu)){var e=function(e){var t=e&&e.getNonce;if(e&&!e.isBrowser||"undefined"==typeof window||"undefined"==typeof document)return{__prefetchRu:!0,version:"1.1.0",preload:function(){},destroy:function(){},refresh:function(){}};var n=new Set,r=new WeakMap,o=!1,i=0,a=[],c=new Set,s={prefetch:[],prerender:[],crossOrigin:[]},u=0,l="",d=0,f=0,h=null,p=!1,m=!1,v=null,g=null,w=!1,y=null,b=null,L=!1,E=65,x=80,T=50,O=!1,k=!1,P=!1,S=!1,A="none",N=!1,C=!1,q=!1,I=!1,M=!1,R=/(^|\/)(login|logout|auth|register|cart|basket|add|delete|remove)(\/|$|\.)/i,_=/\.(pdf|doc|docx|xls|xlsx|zip|rar|exe)($|\?)/i;function D(){if(!o){var e=document.body;if(e){l=location.origin+location.pathname+location.search,g=void 0!==window.BX?"bitrix":void 0!==window.B24||void 0!==window.BX24?"bitrix24":document.querySelector(".t-records")||void 0!==window.Tilda?"tilda":null;var t=e.dataset;if(O="prefetchAllowQueryString"in t||"instantAllowQueryString"in t,k="prefetchAllowExternalLinks"in t||"instantAllowExternalLinks"in t,P="prefetchWhitelist"in t||"instantWhitelist"in t,t.prefetchNonce&&(b=t.prefetchNonce),!b&&t.instantNonce&&(b=t.instantNonce),!m&&("prefetchSpecrules"in t||"instantSpecrules"in t)&&HTMLScriptElement.supports&&HTMLScriptElement.supports("speculationrules")){var n=t.prefetchSpecrules||t.instantSpecrules;"prerender"===n?(A="prerender",S=!0):"no"!==n&&(A="prefetch",S=!0)}N="prefetchSpecrulesFallback"in t||"instantSpecrulesFallback"in t,C="prefetchPrerenderAll"in t||"instantPrerenderAll"in t;var r=t.prefetchIntensity||t.instantIntensity;if("mousedown"===r)q=!0;else if("viewport"===r||"viewport-all"===r)("viewport-all"===r||p&&U())&&(I=!0);else if(r){var i=parseInt(r,10);!isNaN(i)&&i>=0&&(E=i)}p&&(x=Math.max(60,Math.min(E||0,150))),(M="prefetchObserveDom"in t||"instantObserveDom"in t)||"bitrix"!==g&&"tilda"!==g||(M=!0),window.addEventListener("popstate",W),window.addEventListener("hashchange",W),window.addEventListener("pageshow",B),"tilda"===g&&E<100&&(E=100);var a={capture:!0,passive:!0};document.addEventListener("touchstart",K,a),q?document.addEventListener("mousedown",G,a):document.addEventListener("mouseover",j,a),I&&"undefined"==typeof IntersectionObserver&&(I=!1),I&&(window.requestIdleCallback||function(e){setTimeout(e,1)})(ee,{timeout:1500}),M&&I&&"undefined"!=typeof MutationObserver&&(o||ne||(ne=new MutationObserver(function(e){var t=!1;e:for(var n=0;n<e.length;n++)for(var r=e[n].addedNodes,o=0;o<r.length;o++){var i=r[o];if(1===i.nodeType&&("A"===i.tagName||i.querySelector&&i.querySelector("a"))){t=!0;break e}}t&&Z&&(clearTimeout(re),re=setTimeout(te,100))})).observe(document.body,{childList:!0,subtree:!0}))}}}function U(){return!w&&"slow-2g"!==y&&"2g"!==y&&"3g"!==y}function W(){l=location.origin+location.pathname+location.search}function B(e){e&&e.persisted&&W()}function z(e){return e?(e.nodeType&&1!==e.nodeType&&(e=e.parentElement),e&&"function"==typeof e.closest?e.closest("a"):null):null}function K(e){if(!(o||e&&!1===e.isTrusted)){d=Date.now();var t=z(e.target);if(H(t)){f&&(clearTimeout(f),f=0),h&&(document.removeEventListener("touchmove",h,!0),document.removeEventListener("scroll",h,!0),h=null);var n=!1;h=function(){n=!0,f&&(clearTimeout(f),f=0),document.removeEventListener("touchmove",h,!0),document.removeEventListener("scroll",h,!0),h=null},document.addEventListener("touchmove",h,{capture:!0,passive:!0,once:!0}),document.addEventListener("scroll",h,{capture:!0,passive:!0,once:!0}),f=setTimeout(function(){h&&(document.removeEventListener("touchmove",h,!0),document.removeEventListener("scroll",h,!0),h=null),f=0,n||Q(t.href,t)},x)}}}function j(e){if(!o&&!(e&&!1===e.isTrusted||d&&Date.now()-d<2500)){var t=z(e.target);if(t&&!r.has(t)&&H(t)){t.addEventListener("mouseleave",F,{passive:!0,once:!0});var n=setTimeout(function(){Q(t.href,t),r.delete(t)},E);r.set(t,n)}}}function F(e){var t=e.currentTarget;if(t){var n=r.get(t);n&&(clearTimeout(n),r.delete(t))}}function G(e){if(!o&&!(e&&!1===e.isTrusted||"number"==typeof e.button&&(1===e.button||2===e.button)||e.metaKey||e.ctrlKey||e.shiftKey||e.altKey||d&&Date.now()-d<2500)){var t=z(e.target);H(t)&&Q(t.href,t)}}function H(e){if(!e)return!1;var t=e.getAttribute("href");if(null===t||""===t.trim())return!1;if(!e.href)return!1;if(e.target&&"_self"!==e.target)return!1;if(e.hasAttribute("download"))return!1;if("noPrefetch"in e.dataset||"prefetchNo"in e.dataset)return!1;if(P&&!("prefetch"in e.dataset)&&!("instant"in e.dataset))return!1;if("http:"!==e.protocol&&"https:"!==e.protocol)return!1;if("http:"===e.protocol&&"https:"===location.protocol)return!1;if(e.origin!==location.origin){if(!k&&!("prefetch"in e.dataset)&&!("instant"in e.dataset))return!1;if(!v)return!1}if(e.search&&!O&&!("prefetch"in e.dataset)&&!("instant"in e.dataset))return!1;if(e.hash&&e.pathname+e.search===location.pathname+location.search)return!1;var r=e.origin+e.pathname+e.search;return r!==l&&!n.has(r)&&!!function(e){var t=e.href,n=e.pathname||"",r=e.hash||"";if("bitrix"===g||"bitrix24"===g){if(-1!==t.indexOf("/bitrix/")||-1!==t.indexOf("sessid="))return!1;if(e.classList.contains("bx-ajax"))return!1}return("tilda"!==g||-1===r.indexOf("#popup:")&&-1===r.indexOf("#rec"))&&(!R.test(n)&&!_.test(n))}(e)&&!!function(e){var t=e.className||"",n=e.hostname||"";return!(-1!==t.indexOf("ym-")||"mc.yandex.ru"===n||"metrika.yandex.ru"===n||-1!==t.indexOf("ga-")||-1!==t.indexOf("gtm-")||"google-analytics.com"===n||n.endsWith(".google-analytics.com")||"googletagmanager.com"===n||n.endsWith(".googletagmanager.com")||-1!==t.indexOf("piwik")||-1!==t.indexOf("matomo")||"matomo.org"===n||n.endsWith(".matomo.org")||"piwik.org"===n||n.endsWith(".piwik.org"))}(e)}function Q(e,t){if(!o&&U()){var r=function(e){try{var t=new URL(e,location.href),n=t.origin+t.pathname+t.search;return t.hash="",{requestUrl:t.href,key:n}}catch(t){return{requestUrl:e,key:e}}}(e),c=r.requestUrl,s=r.key;if(!n.has(s)){n.size>=T&&n.delete(n.values().next().value),n.add(s);var u=function(e){return S&&"none"!==A?"prerender"!==A?A:C||P||e&&e.dataset&&("prefetchPrerender"in e.dataset||"instantPrerender"in e.dataset)?"prerender":"prefetch":"none"}(t);if(i>=4)return a.length>=50?void n.delete(s):void a.push({url:c,key:s,mode:u});X(c,s,u)}}}function X(e,t,n){if("none"===n)m||!L?Y(e,t):V(e,t);else{var r=!1;try{!function(e,t){var n=!1;try{n=new URL(e,location.href).origin!==location.origin}catch(e){}if(n&&"prerender"===t&&(t="prefetch"),n?s.crossOrigin.push(e):"prerender"===t?s.prerender.push(e):s.prefetch.push(e),!u){var r=window.requestIdleCallback||function(e){setTimeout(e,1)};u=r(J,{timeout:50})}}(e,n),r=!0}catch(e){}!N&&r||(m||!L?Y(e,t):V(e,t))}}function $(){for(;a.length>0&&i<4;){var e=a.shift();X(e.url,e.key,e.mode)}}function J(){if(u=0,!o){var e=document.head;if(e){var t={};if(s.prefetch.length>0&&(t.prefetch=t.prefetch||[],t.prefetch.push({source:"list",urls:s.prefetch.slice()}),s.prefetch.length=0),s.prerender.length>0&&(t.prerender=t.prerender||[],t.prerender.push({source:"list",urls:s.prerender.slice()}),s.prerender.length=0),s.crossOrigin.length>0&&(t.prefetch=t.prefetch||[],t.prefetch.push({source:"list",urls:s.crossOrigin.slice(),referrer_policy:"no-referrer",requires:["anonymous-client-ip-when-cross-origin"]}),s.crossOrigin.length=0),t.prefetch||t.prerender){var n=document.createElement("script");n.type="speculationrules",b&&(n.nonce=b),n.textContent=JSON.stringify(t),e.appendChild(n),e.removeChild(n)}}}}function V(e,t){var r=document.head;if(r){i++;var o=document.createElement("link");o.rel="prefetch",o.href=e,o.as="document";try{o.fetchPriority="low"}catch(e){}try{new URL(e,location.href).origin!==location.origin&&(o.referrerPolicy="no-referrer",o.crossOrigin="anonymous")}catch(e){}var a=setTimeout(function(){a=0,n.delete(t),c()},3e4);o.onload=c,o.onerror=function(){n.delete(t),c()},r.appendChild(o)}else n.delete(t);function c(){a&&(clearTimeout(a),a=0),o.onload=o.onerror=null,o.parentNode&&o.parentNode.removeChild(o),i--,$()}}function Y(e,t){if("function"==typeof fetch){i++;var r=!1,o=null,a=0;"undefined"!=typeof AbortController&&(o=new AbortController,c.add(o),a=setTimeout(function(){try{o.abort()}catch(e){}l(!1)},5e3));var s=!1;try{s=new URL(e,location.href).origin!==location.origin}catch(e){}var u={method:"GET",cache:"force-cache",credentials:s?"omit":"same-origin",headers:{Accept:"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"}};s||(u.headers.Purpose="prefetch"),s&&(u.referrerPolicy="no-referrer"),o&&(u.signal=o.signal);try{fetch(e,u).then(function(e){l(e&&(e.ok||304===e.status))}).catch(function(){l(!1)})}catch(e){l(!1)}}else n.delete(t);function l(e){r||(r=!0,a&&clearTimeout(a),o&&c.delete(o),e||n.delete(t),i--,$())}}!function(){if(t)try{b=t()}catch(e){}try{var e=document.createElement("link");e.relList&&"function"==typeof e.relList.supports&&(L=e.relList.supports("prefetch"))}catch(e){}var n=navigator.userAgent,r=navigator.userAgentData;if(r){m=!1;var o="Android"===r.platform;p=r.mobile||!1;for(var i=r.brands||[],a=0;a<i.length;a++){var c=i[a];if("Chromium"===c.brand||"Google Chrome"===c.brand){v=parseInt(c.version,10);break}}}else{m=/iPad|iPhone/.test(n)||"MacIntel"===navigator.platform&&navigator.maxTouchPoints>1,o=/Android/.test(n),p=(m||o)&&Math.min(screen.width,screen.height)<768;var s=n.match(/Chrome\/(\d+)/);s&&(v=parseInt(s[1],10))}p&&(T=20);var u=navigator.connection;u&&(y=u.effectiveType,w=u.saveData||!1),"loading"===document.readyState?document.addEventListener("DOMContentLoaded",D):D()}();var Z=null;function ee(){o||Z||(Z=new IntersectionObserver(function(e){e.forEach(function(e){e.isIntersecting&&(Z.unobserve(e.target),H(e.target)&&Q(e.target.href,e.target))})},{rootMargin:p?"100px":"200px"}),te())}function te(){Z&&document.querySelectorAll("a").forEach(function(e){H(e)&&Z.observe(e)})}var ne=null,re=null;return{__prefetchRu:!0,version:"1.1.0",preload:function(e){if(function(e){return!(!e||"string"!=typeof e||!(e=e.trim())||/^\/\//.test(e)||/^(javascript|data|vbscript|file):/i.test(e)||!(/^https?:\/\//i.test(e)||/^\//.test(e)||/^\./.test(e))&&/^[a-z][a-z0-9+.-]*:/i.test(e))}(e)){var t=document.createElement("a");t.setAttribute("href",e.trim()),H(t)&&Q(t.href,t)}},destroy:function(){o=!0,a.length=0,f&&(clearTimeout(f),f=0),h&&(document.removeEventListener("touchmove",h,!0),document.removeEventListener("scroll",h,!0),h=null),c.forEach(function(e){try{e.abort()}catch(e){}}),c.clear(),u&&((window.cancelIdleCallback||clearTimeout)(u),u=0),s.prefetch.length=s.prerender.length=s.crossOrigin.length=0;var e={capture:!0,passive:!0};document.removeEventListener("touchstart",K,e),document.removeEventListener("mouseover",j,e),document.removeEventListener("mousedown",G,e),window.removeEventListener("popstate",W),window.removeEventListener("hashchange",W),window.removeEventListener("pageshow",B),Z&&(Z.disconnect(),Z=null),ne&&(ne.disconnect(),ne=null)},refresh:W}}({isBrowser:!0,getNonce:function(){try{var e=document.currentScript;if(e&&e.nonce)return e.nonce}catch(e){}return null}});window.PrefetchRu=e,window.Prefetch||(window.Prefetch=e)}}();
6
+ !function(){"use strict";if(!(window.PrefetchRu&&window.PrefetchRu.__prefetchRu||window.Prefetch&&window.Prefetch.__prefetchRu)){var e=function(e){var t=e&&e.getNonce;if(e&&!e.isBrowser||"undefined"==typeof window||"undefined"==typeof document)return{__prefetchRu:!0,version:"1.1.2",preload:function(){},destroy:function(){},refresh:function(){}};var n=new Set,r=new WeakMap,o=!1,i=0,a=[],c=new Set,s={prefetch:[],prerender:[],crossOrigin:[]},l=0,u="",d=0,f=0,h=null,p=!1,m=!1,v=null,g=!1,w=null,y=null,b=!1,L=65,E=80,x=50,T=!1,O=!1,k=!1,P=!1,S="none",A=!1,N=!1,C=!1,q=!1,I=!1,R=/(^|\/)(login|logout|auth|register|cart|basket|add|delete|remove)(\/|$|\.)/i,M=/\.(pdf|doc|docx|xls|xlsx|zip|rar|exe)($|\?)/i;function _(){if(!o){var e=document.body;if(e){u=location.origin+location.pathname+location.search,v=void 0!==window.BX?"bitrix":void 0!==window.B24||void 0!==window.BX24?"bitrix24":document.querySelector(".t-records")||void 0!==window.Tilda?"tilda":null;var t=e.dataset;if(T="prefetchAllowQueryString"in t||"instantAllowQueryString"in t,O="prefetchAllowExternalLinks"in t||"instantAllowExternalLinks"in t,k="prefetchWhitelist"in t||"instantWhitelist"in t,t.prefetchNonce&&(y=t.prefetchNonce),!y&&t.instantNonce&&(y=t.instantNonce),!m&&("prefetchSpecrules"in t||"instantSpecrules"in t)&&HTMLScriptElement.supports&&HTMLScriptElement.supports("speculationrules")){var n=t.prefetchSpecrules||t.instantSpecrules;"prerender"===n?(S="prerender",P=!0):"no"!==n&&(S="prefetch",P=!0)}A="prefetchSpecrulesFallback"in t||"instantSpecrulesFallback"in t,N="prefetchPrerenderAll"in t||"instantPrerenderAll"in t;var r=t.prefetchIntensity||t.instantIntensity;if("mousedown"===r)C=!0;else if("viewport"===r||"viewport-all"===r)("viewport-all"===r||p&&D())&&(q=!0);else if(r){var i=parseInt(r,10);!isNaN(i)&&i>=0&&(L=i)}p&&(E=Math.max(60,Math.min(L||0,150))),(I="prefetchObserveDom"in t||"instantObserveDom"in t)||"bitrix"!==v&&"tilda"!==v||(I=!0),window.addEventListener("popstate",U),window.addEventListener("hashchange",U),window.addEventListener("pageshow",W),"tilda"===v&&L<100&&(L=100);var a={capture:!0,passive:!0};document.addEventListener("touchstart",z,a),C?document.addEventListener("mousedown",F,a):document.addEventListener("mouseover",K,a),q&&"undefined"==typeof IntersectionObserver&&(q=!1),q&&(window.requestIdleCallback||function(e){setTimeout(e,1)})(Z,{timeout:1500}),I&&q&&"undefined"!=typeof MutationObserver&&(o||te||(te=new MutationObserver(function(e){var t=!1;e:for(var n=0;n<e.length;n++)for(var r=e[n].addedNodes,o=0;o<r.length;o++){var i=r[o];if(1===i.nodeType&&("A"===i.tagName||i.querySelector&&i.querySelector("a"))){t=!0;break e}}t&&Y&&(clearTimeout(ne),ne=setTimeout(ee,100))})).observe(document.body,{childList:!0,subtree:!0}))}}}function D(){return!g&&"slow-2g"!==w&&"2g"!==w&&"3g"!==w}function U(){u=location.origin+location.pathname+location.search}function W(e){e&&e.persisted&&U()}function B(e){return e?(e.nodeType&&1!==e.nodeType&&(e=e.parentElement),e&&"function"==typeof e.closest?e.closest("a"):null):null}function z(e){if(!(o||e&&!1===e.isTrusted)){d=Date.now();var t=B(e.target);if(G(t)){f&&(clearTimeout(f),f=0),h&&(document.removeEventListener("touchmove",h,!0),document.removeEventListener("scroll",h,!0),h=null);var n=!1;h=function(){n=!0,f&&(clearTimeout(f),f=0),document.removeEventListener("touchmove",h,!0),document.removeEventListener("scroll",h,!0),h=null},document.addEventListener("touchmove",h,{capture:!0,passive:!0,once:!0}),document.addEventListener("scroll",h,{capture:!0,passive:!0,once:!0}),f=setTimeout(function(){h&&(document.removeEventListener("touchmove",h,!0),document.removeEventListener("scroll",h,!0),h=null),f=0,n||H(t.href,t)},E)}}}function K(e){if(!o&&!(e&&!1===e.isTrusted||d&&Date.now()-d<2500)){var t=B(e.target);if(t&&!r.has(t)&&G(t)){t.addEventListener("mouseleave",j,{passive:!0,once:!0});var n=setTimeout(function(){H(t.href,t),r.delete(t)},L);r.set(t,n)}}}function j(e){var t=e.currentTarget;if(t){var n=r.get(t);n&&(clearTimeout(n),r.delete(t))}}function F(e){if(!o&&!(e&&!1===e.isTrusted||"number"==typeof e.button&&(1===e.button||2===e.button)||e.metaKey||e.ctrlKey||e.shiftKey||e.altKey||d&&Date.now()-d<2500)){var t=B(e.target);G(t)&&H(t.href,t)}}function G(e){if(!e)return!1;var t=e.getAttribute("href");if(null===t||""===t.trim())return!1;if(!e.href)return!1;if(e.target&&"_self"!==e.target)return!1;if(e.hasAttribute("download"))return!1;if("noPrefetch"in e.dataset||"prefetchNo"in e.dataset)return!1;if(k&&!("prefetch"in e.dataset)&&!("instant"in e.dataset))return!1;if("http:"!==e.protocol&&"https:"!==e.protocol)return!1;if("http:"===e.protocol&&"https:"===location.protocol)return!1;if(e.origin!==location.origin&&!O&&!("prefetch"in e.dataset)&&!("instant"in e.dataset))return!1;if(e.search&&!T&&!("prefetch"in e.dataset)&&!("instant"in e.dataset))return!1;if(e.hash&&e.pathname+e.search===location.pathname+location.search)return!1;var r=e.origin+e.pathname+e.search;return r!==u&&!n.has(r)&&!!function(e){var t=e.href,n=e.pathname||"",r=e.hash||"";if("bitrix"===v||"bitrix24"===v){if(-1!==t.indexOf("/bitrix/")||-1!==t.indexOf("sessid="))return!1;if(e.classList.contains("bx-ajax"))return!1}return("tilda"!==v||-1===r.indexOf("#popup:")&&-1===r.indexOf("#rec"))&&(!R.test(n)&&!M.test(n))}(e)&&!!function(e){var t=e.className||"",n=e.hostname||"";return!(-1!==t.indexOf("ym-")||"mc.yandex.ru"===n||"metrika.yandex.ru"===n||-1!==t.indexOf("ga-")||-1!==t.indexOf("gtm-")||"google-analytics.com"===n||n.endsWith(".google-analytics.com")||"googletagmanager.com"===n||n.endsWith(".googletagmanager.com")||-1!==t.indexOf("piwik")||-1!==t.indexOf("matomo")||"matomo.org"===n||n.endsWith(".matomo.org")||"piwik.org"===n||n.endsWith(".piwik.org"))}(e)}function H(e,t){if(!o&&D()){var r=function(e){try{var t=new URL(e,location.href),n=t.origin+t.pathname+t.search;return t.hash="",{requestUrl:t.href,key:n}}catch(t){return{requestUrl:e,key:e}}}(e),c=r.requestUrl,s=r.key;if(!n.has(s)){n.size>=x&&n.delete(n.values().next().value),n.add(s);var l=function(e){return P&&"none"!==S?"prerender"!==S?S:N||k||e&&e.dataset&&("prefetchPrerender"in e.dataset||"instantPrerender"in e.dataset)?"prerender":"prefetch":"none"}(t);if(i>=4)return a.length>=50?void n.delete(s):void a.push({url:c,key:s,mode:l});Q(c,s,l)}}}function Q(e,t,n){var r=!1;try{r=new URL(e,location.href).origin!==location.origin}catch(e){}if("none"===n)m||!b||r?V(e,t):J(e,t);else{var o=!1;try{!function(e,t){var n=!1;try{n=new URL(e,location.href).origin!==location.origin}catch(e){}if(n&&"prerender"===t&&(t="prefetch"),n?s.crossOrigin.push(e):"prerender"===t?s.prerender.push(e):s.prefetch.push(e),!l){var r=window.requestIdleCallback||function(e){setTimeout(e,1)};l=r($,{timeout:50})}}(e,n),o=!0}catch(e){}!A&&o||(m||!b||r?V(e,t):J(e,t))}}function X(){for(;a.length>0&&i<4;){var e=a.shift();Q(e.url,e.key,e.mode)}}function $(){if(l=0,!o){var e=document.head;if(e){var t={};if(s.prefetch.length>0&&(t.prefetch=t.prefetch||[],t.prefetch.push({source:"list",urls:s.prefetch.slice()}),s.prefetch.length=0),s.prerender.length>0&&(t.prerender=t.prerender||[],t.prerender.push({source:"list",urls:s.prerender.slice()}),s.prerender.length=0),s.crossOrigin.length>0&&(t.prefetch=t.prefetch||[],t.prefetch.push({source:"list",urls:s.crossOrigin.slice(),referrer_policy:"no-referrer",requires:["anonymous-client-ip-when-cross-origin"]}),s.crossOrigin.length=0),t.prefetch||t.prerender){var n=document.createElement("script");n.type="speculationrules",y&&(n.nonce=y),n.textContent=JSON.stringify(t),e.appendChild(n),e.removeChild(n)}}}}function J(e,t){var r=document.head;if(r){i++;var o=document.createElement("link");o.rel="prefetch",o.href=e,o.as="document";try{o.fetchPriority="low"}catch(e){}try{new URL(e,location.href).origin!==location.origin&&(o.referrerPolicy="no-referrer",o.crossOrigin="anonymous")}catch(e){}var a=setTimeout(function(){a=0,n.delete(t),c()},3e4);o.onload=c,o.onerror=function(){n.delete(t),c()},r.appendChild(o)}else n.delete(t);function c(){a&&(clearTimeout(a),a=0),o.onload=o.onerror=null,o.parentNode&&o.parentNode.removeChild(o),i--,X()}}function V(e,t){if("function"==typeof fetch){i++;var r=!1,o=null,a=0;"undefined"!=typeof AbortController&&(o=new AbortController,c.add(o),a=setTimeout(function(){try{o.abort()}catch(e){}u(!1)},5e3));var s=!1;try{s=new URL(e,location.href).origin!==location.origin}catch(e){}var l={method:"GET",cache:"force-cache",credentials:s?"omit":"same-origin",mode:s?"no-cors":"cors"};s||(l.headers={Accept:"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",Purpose:"prefetch"}),s&&(l.referrerPolicy="no-referrer"),o&&(l.signal=o.signal);try{fetch(e,l).then(function(e){u(e&&(e.ok||304===e.status||"opaque"===e.type))}).catch(function(){u(!1)})}catch(e){u(!1)}}else n.delete(t);function u(e){r||(r=!0,a&&clearTimeout(a),o&&c.delete(o),e||n.delete(t),i--,X())}}!function(){if(t)try{y=t()}catch(e){}try{var e=document.createElement("link");e.relList&&"function"==typeof e.relList.supports&&(b=e.relList.supports("prefetch"))}catch(e){}var n=navigator.userAgent,r=navigator.userAgentData;if(r){m=!1;var o="Android"===r.platform;p=r.mobile||!1;for(var i=r.brands||[],a=0;a<i.length;a++){var c=i[a];if("Chromium"===c.brand||"Google Chrome"===c.brand){parseInt(c.version,10);break}}}else{m=/iPad|iPhone/.test(n)||"MacIntel"===navigator.platform&&navigator.maxTouchPoints>1,o=/Android/.test(n),p=(m||o)&&Math.min(screen.width,screen.height)<768;var s=n.match(/Chrome\/(\d+)/);s&&parseInt(s[1],10)}p&&(x=20);var l=navigator.connection;l&&(w=l.effectiveType,g=l.saveData||!1),"loading"===document.readyState?document.addEventListener("DOMContentLoaded",_):_()}();var Y=null;function Z(){o||Y||(Y=new IntersectionObserver(function(e){e.forEach(function(e){e.isIntersecting&&(Y.unobserve(e.target),G(e.target)&&H(e.target.href,e.target))})},{rootMargin:p?"100px":"200px"}),ee())}function ee(){Y&&document.querySelectorAll("a").forEach(function(e){G(e)&&Y.observe(e)})}var te=null,ne=null;return{__prefetchRu:!0,version:"1.1.2",preload:function(e){if(function(e){return!(!e||"string"!=typeof e||!(e=e.trim())||/^\/\//.test(e)||/^(javascript|data|vbscript|file):/i.test(e)||!(/^https?:\/\//i.test(e)||/^\//.test(e)||/^\./.test(e))&&/^[a-z][a-z0-9+.-]*:/i.test(e))}(e)){var t=document.createElement("a");t.setAttribute("href",e.trim()),G(t)&&H(t.href,t)}},destroy:function(){o=!0,a.length=0,f&&(clearTimeout(f),f=0),h&&(document.removeEventListener("touchmove",h,!0),document.removeEventListener("scroll",h,!0),h=null),c.forEach(function(e){try{e.abort()}catch(e){}}),c.clear(),l&&((window.cancelIdleCallback||clearTimeout)(l),l=0),s.prefetch.length=s.prerender.length=s.crossOrigin.length=0;var e={capture:!0,passive:!0};document.removeEventListener("touchstart",z,e),document.removeEventListener("mouseover",K,e),document.removeEventListener("mousedown",F,e),window.removeEventListener("popstate",U),window.removeEventListener("hashchange",U),window.removeEventListener("pageshow",W),Y&&(Y.disconnect(),Y=null),te&&(te.disconnect(),te=null)},refresh:U}}({isBrowser:!0,getNonce:function(){try{var e=document.currentScript;if(e&&e.nonce)return e.nonce}catch(e){}return null}});window.PrefetchRu=e,window.Prefetch||(window.Prefetch=e)}}();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prefetchru/prefetch",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "description": "Мгновенная загрузка страниц для российского веба. Instant page loading for Russian web.",
5
5
  "main": "prefetch.js",
6
6
  "module": "prefetch.esm.js",
package/prefetch.esm.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * prefetch.ru v1.1.0 (ESM) - Мгновенная загрузка страниц
2
+ * prefetch.ru v1.1.2 (ESM) - Мгновенная загрузка страниц
3
3
  * © 2026 Сергей Макаров | MIT License
4
4
  * https://prefetch.ru | https://github.com/prefetch-ru
5
5
  */
@@ -19,7 +19,7 @@ function createPrefetchCore(options) {
19
19
  if (!isBrowser || typeof window === 'undefined' || typeof document === 'undefined') {
20
20
  return {
21
21
  __prefetchRu: true,
22
- version: '1.1.0',
22
+ version: '1.1.2',
23
23
  preload: function () {},
24
24
  destroy: function () {},
25
25
  refresh: function () {}
@@ -53,7 +53,6 @@ function createPrefetchCore(options) {
53
53
 
54
54
  var isMobile = false;
55
55
  var isIOS = false;
56
- var chromiumVer = null;
57
56
  var platform = null;
58
57
  var saveData = false;
59
58
  var connType = null;
@@ -115,7 +114,7 @@ function createPrefetchCore(options) {
115
114
  for (var i = 0; i < brands.length; i++) {
116
115
  var b = brands[i];
117
116
  if (b.brand === 'Chromium' || b.brand === 'Google Chrome') {
118
- chromiumVer = parseInt(b.version, 10);
117
+ parseInt(b.version, 10);
119
118
  break
120
119
  }
121
120
  }
@@ -128,7 +127,7 @@ function createPrefetchCore(options) {
128
127
  isMobile = (isIOS || isAndroid) && Math.min(screen.width, screen.height) < 768;
129
128
  // Chromium версия из UA
130
129
  var cm = ua.match(/Chrome\/(\d+)/);
131
- if (cm) chromiumVer = parseInt(cm[1], 10);
130
+ if (cm) parseInt(cm[1], 10);
132
131
  }
133
132
  if (isMobile) maxPreloads = 20;
134
133
 
@@ -416,7 +415,7 @@ function createPrefetchCore(options) {
416
415
  // Внешние ссылки
417
416
  if (a.origin !== location.origin) {
418
417
  if (!allowExternal && !('prefetch' in a.dataset) && !('instant' in a.dataset)) return false
419
- if (!chromiumVer) return false
418
+ // v1.1.1: убрано ограничение chromiumVer Firefox и Safari тоже поддерживают cross-origin prefetch
420
419
  }
421
420
 
422
421
  // Query string
@@ -546,6 +545,13 @@ function createPrefetchCore(options) {
546
545
  }
547
546
 
548
547
  function doPreload(requestUrl, key, mode) {
548
+ // v1.1.1: определяем cross-origin для выбора метода
549
+ var isCrossOrigin = false;
550
+ try {
551
+ var u = new URL(requestUrl, location.href);
552
+ isCrossOrigin = u.origin !== location.origin;
553
+ } catch (e) {}
554
+
549
555
  if (mode !== 'none') {
550
556
  // v1.0.11: try/catch для preloadSpec — при строгом CSP/Trusted Types может выбросить исключение
551
557
  var specOk = false;
@@ -559,13 +565,15 @@ function createPrefetchCore(options) {
559
565
  // v1.0.11: fallback только если явно включён ИЛИ если SpecRules не удался
560
566
  // По умолчанию fallback отключён для избежания двойного трафика
561
567
  if (specRulesFallback || !specOk) {
562
- if (isIOS || !supportsLinkPrefetch) preloadFetch(requestUrl, key);
568
+ // v1.1.1: cross-origin всегда через fetch (no-cors), <link> требует CORS headers
569
+ if (isIOS || !supportsLinkPrefetch || isCrossOrigin) preloadFetch(requestUrl, key);
563
570
  else preloadLink(requestUrl, key);
564
571
  }
565
572
  return
566
573
  }
567
574
 
568
- if (isIOS || !supportsLinkPrefetch) preloadFetch(requestUrl, key);
575
+ // v1.1.1: cross-origin всегда через fetch (no-cors), <link crossorigin=anonymous> требует CORS
576
+ if (isIOS || !supportsLinkPrefetch || isCrossOrigin) preloadFetch(requestUrl, key);
569
577
  else preloadLink(requestUrl, key);
570
578
  }
571
579
 
@@ -743,15 +751,16 @@ function createPrefetchCore(options) {
743
751
  cache: 'force-cache',
744
752
  // v1.0.13: для cross-origin: omit credentials, no-referrer (избегаем CORS preflight и утечки referrer)
745
753
  credentials: isCrossOrigin ? 'omit' : 'same-origin',
746
- // v1.0.11: Accept header для корректного content negotiation
747
- headers: {
748
- Accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'
749
- }
754
+ // v1.1.1: для cross-origin используем no-cors mode (opaque response, но кэш прогревается)
755
+ mode: isCrossOrigin ? 'no-cors' : 'cors'
750
756
  };
751
757
 
752
- // v1.0.13: Purpose header только для same-origin (избегаем CORS preflight на cross-origin)
758
+ // v1.1.1: headers только для same-origin (no-cors не позволяет кастомные headers)
753
759
  if (!isCrossOrigin) {
754
- opts.headers.Purpose = 'prefetch';
760
+ opts.headers = {
761
+ Accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
762
+ Purpose: 'prefetch'
763
+ };
755
764
  }
756
765
 
757
766
  // v1.0.13: referrerPolicy для cross-origin (приватность)
@@ -764,8 +773,9 @@ function createPrefetchCore(options) {
764
773
  try {
765
774
  fetch(url, opts)
766
775
  .then(function (r) {
767
- // v1.0.12: 304 Not Modified тоже считаем успехом (кэш прогрет)
768
- done(r && (r.ok || r.status === 304));
776
+ // v1.1.1: для no-cors mode response.type === 'opaque', r.ok === false, но кэш прогрет
777
+ // v1.0.12: 304 Not Modified тоже считаем успехом
778
+ done(r && (r.ok || r.status === 304 || r.type === 'opaque'));
769
779
  })
770
780
  .catch(function () {
771
781
  done(false);
@@ -908,7 +918,7 @@ function createPrefetchCore(options) {
908
918
  // Публичный API
909
919
  var api = {
910
920
  __prefetchRu: true,
911
- version: '1.1.0',
921
+ version: '1.1.2',
912
922
  preload: function (url) {
913
923
  // v1.0.11: валидация URL + прогон через canPreload() (консистентность с авто-режимом)
914
924
  if (!isValidPrefetchUrl(url)) return
package/prefetch.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * prefetch.ru v1.1.0 - Мгновенная загрузка страниц
2
+ * prefetch.ru v1.1.2 - Мгновенная загрузка страниц
3
3
  * © 2026 Сергей Макаров | MIT License
4
4
  * https://prefetch.ru | https://github.com/prefetch-ru
5
5
  */
@@ -22,7 +22,7 @@
22
22
  if (!isBrowser || typeof window === 'undefined' || typeof document === 'undefined') {
23
23
  return {
24
24
  __prefetchRu: true,
25
- version: '1.1.0',
25
+ version: '1.1.2',
26
26
  preload: function () {},
27
27
  destroy: function () {},
28
28
  refresh: function () {}
@@ -56,7 +56,6 @@
56
56
 
57
57
  var isMobile = false;
58
58
  var isIOS = false;
59
- var chromiumVer = null;
60
59
  var platform = null;
61
60
  var saveData = false;
62
61
  var connType = null;
@@ -118,7 +117,7 @@
118
117
  for (var i = 0; i < brands.length; i++) {
119
118
  var b = brands[i];
120
119
  if (b.brand === 'Chromium' || b.brand === 'Google Chrome') {
121
- chromiumVer = parseInt(b.version, 10);
120
+ parseInt(b.version, 10);
122
121
  break
123
122
  }
124
123
  }
@@ -131,7 +130,7 @@
131
130
  isMobile = (isIOS || isAndroid) && Math.min(screen.width, screen.height) < 768;
132
131
  // Chromium версия из UA
133
132
  var cm = ua.match(/Chrome\/(\d+)/);
134
- if (cm) chromiumVer = parseInt(cm[1], 10);
133
+ if (cm) parseInt(cm[1], 10);
135
134
  }
136
135
  if (isMobile) maxPreloads = 20;
137
136
 
@@ -419,7 +418,7 @@
419
418
  // Внешние ссылки
420
419
  if (a.origin !== location.origin) {
421
420
  if (!allowExternal && !('prefetch' in a.dataset) && !('instant' in a.dataset)) return false
422
- if (!chromiumVer) return false
421
+ // v1.1.1: убрано ограничение chromiumVer Firefox и Safari тоже поддерживают cross-origin prefetch
423
422
  }
424
423
 
425
424
  // Query string
@@ -549,6 +548,13 @@
549
548
  }
550
549
 
551
550
  function doPreload(requestUrl, key, mode) {
551
+ // v1.1.1: определяем cross-origin для выбора метода
552
+ var isCrossOrigin = false;
553
+ try {
554
+ var u = new URL(requestUrl, location.href);
555
+ isCrossOrigin = u.origin !== location.origin;
556
+ } catch (e) {}
557
+
552
558
  if (mode !== 'none') {
553
559
  // v1.0.11: try/catch для preloadSpec — при строгом CSP/Trusted Types может выбросить исключение
554
560
  var specOk = false;
@@ -562,13 +568,15 @@
562
568
  // v1.0.11: fallback только если явно включён ИЛИ если SpecRules не удался
563
569
  // По умолчанию fallback отключён для избежания двойного трафика
564
570
  if (specRulesFallback || !specOk) {
565
- if (isIOS || !supportsLinkPrefetch) preloadFetch(requestUrl, key);
571
+ // v1.1.1: cross-origin всегда через fetch (no-cors), <link> требует CORS headers
572
+ if (isIOS || !supportsLinkPrefetch || isCrossOrigin) preloadFetch(requestUrl, key);
566
573
  else preloadLink(requestUrl, key);
567
574
  }
568
575
  return
569
576
  }
570
577
 
571
- if (isIOS || !supportsLinkPrefetch) preloadFetch(requestUrl, key);
578
+ // v1.1.1: cross-origin всегда через fetch (no-cors), <link crossorigin=anonymous> требует CORS
579
+ if (isIOS || !supportsLinkPrefetch || isCrossOrigin) preloadFetch(requestUrl, key);
572
580
  else preloadLink(requestUrl, key);
573
581
  }
574
582
 
@@ -746,15 +754,16 @@
746
754
  cache: 'force-cache',
747
755
  // v1.0.13: для cross-origin: omit credentials, no-referrer (избегаем CORS preflight и утечки referrer)
748
756
  credentials: isCrossOrigin ? 'omit' : 'same-origin',
749
- // v1.0.11: Accept header для корректного content negotiation
750
- headers: {
751
- Accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'
752
- }
757
+ // v1.1.1: для cross-origin используем no-cors mode (opaque response, но кэш прогревается)
758
+ mode: isCrossOrigin ? 'no-cors' : 'cors'
753
759
  };
754
760
 
755
- // v1.0.13: Purpose header только для same-origin (избегаем CORS preflight на cross-origin)
761
+ // v1.1.1: headers только для same-origin (no-cors не позволяет кастомные headers)
756
762
  if (!isCrossOrigin) {
757
- opts.headers.Purpose = 'prefetch';
763
+ opts.headers = {
764
+ Accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
765
+ Purpose: 'prefetch'
766
+ };
758
767
  }
759
768
 
760
769
  // v1.0.13: referrerPolicy для cross-origin (приватность)
@@ -767,8 +776,9 @@
767
776
  try {
768
777
  fetch(url, opts)
769
778
  .then(function (r) {
770
- // v1.0.12: 304 Not Modified тоже считаем успехом (кэш прогрет)
771
- done(r && (r.ok || r.status === 304));
779
+ // v1.1.1: для no-cors mode response.type === 'opaque', r.ok === false, но кэш прогрет
780
+ // v1.0.12: 304 Not Modified тоже считаем успехом
781
+ done(r && (r.ok || r.status === 304 || r.type === 'opaque'));
772
782
  })
773
783
  .catch(function () {
774
784
  done(false);
@@ -911,7 +921,7 @@
911
921
  // Публичный API
912
922
  var api = {
913
923
  __prefetchRu: true,
914
- version: '1.1.0',
924
+ version: '1.1.2',
915
925
  preload: function (url) {
916
926
  // v1.0.11: валидация URL + прогон через canPreload() (консистентность с авто-режимом)
917
927
  if (!isValidPrefetchUrl(url)) return
package/src/core.js CHANGED
@@ -412,7 +412,7 @@ export function createPrefetchCore(options) {
412
412
  // Внешние ссылки
413
413
  if (a.origin !== location.origin) {
414
414
  if (!allowExternal && !('prefetch' in a.dataset) && !('instant' in a.dataset)) return false
415
- if (!chromiumVer) return false
415
+ // v1.1.1: убрано ограничение chromiumVer Firefox и Safari тоже поддерживают cross-origin prefetch
416
416
  }
417
417
 
418
418
  // Query string
@@ -542,6 +542,13 @@ export function createPrefetchCore(options) {
542
542
  }
543
543
 
544
544
  function doPreload(requestUrl, key, mode) {
545
+ // v1.1.1: определяем cross-origin для выбора метода
546
+ var isCrossOrigin = false
547
+ try {
548
+ var u = new URL(requestUrl, location.href)
549
+ isCrossOrigin = u.origin !== location.origin
550
+ } catch (e) {}
551
+
545
552
  if (mode !== 'none') {
546
553
  // v1.0.11: try/catch для preloadSpec — при строгом CSP/Trusted Types может выбросить исключение
547
554
  var specOk = false
@@ -555,13 +562,15 @@ export function createPrefetchCore(options) {
555
562
  // v1.0.11: fallback только если явно включён ИЛИ если SpecRules не удался
556
563
  // По умолчанию fallback отключён для избежания двойного трафика
557
564
  if (specRulesFallback || !specOk) {
558
- if (isIOS || !supportsLinkPrefetch) preloadFetch(requestUrl, key)
565
+ // v1.1.1: cross-origin всегда через fetch (no-cors), <link> требует CORS headers
566
+ if (isIOS || !supportsLinkPrefetch || isCrossOrigin) preloadFetch(requestUrl, key)
559
567
  else preloadLink(requestUrl, key)
560
568
  }
561
569
  return
562
570
  }
563
571
 
564
- if (isIOS || !supportsLinkPrefetch) preloadFetch(requestUrl, key)
572
+ // v1.1.1: cross-origin всегда через fetch (no-cors), <link crossorigin=anonymous> требует CORS
573
+ if (isIOS || !supportsLinkPrefetch || isCrossOrigin) preloadFetch(requestUrl, key)
565
574
  else preloadLink(requestUrl, key)
566
575
  }
567
576
 
@@ -739,15 +748,16 @@ export function createPrefetchCore(options) {
739
748
  cache: 'force-cache',
740
749
  // v1.0.13: для cross-origin: omit credentials, no-referrer (избегаем CORS preflight и утечки referrer)
741
750
  credentials: isCrossOrigin ? 'omit' : 'same-origin',
742
- // v1.0.11: Accept header для корректного content negotiation
743
- headers: {
744
- Accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'
745
- }
751
+ // v1.1.1: для cross-origin используем no-cors mode (opaque response, но кэш прогревается)
752
+ mode: isCrossOrigin ? 'no-cors' : 'cors'
746
753
  }
747
754
 
748
- // v1.0.13: Purpose header только для same-origin (избегаем CORS preflight на cross-origin)
755
+ // v1.1.1: headers только для same-origin (no-cors не позволяет кастомные headers)
749
756
  if (!isCrossOrigin) {
750
- opts.headers.Purpose = 'prefetch'
757
+ opts.headers = {
758
+ Accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
759
+ Purpose: 'prefetch'
760
+ }
751
761
  }
752
762
 
753
763
  // v1.0.13: referrerPolicy для cross-origin (приватность)
@@ -760,8 +770,9 @@ export function createPrefetchCore(options) {
760
770
  try {
761
771
  fetch(url, opts)
762
772
  .then(function (r) {
763
- // v1.0.12: 304 Not Modified тоже считаем успехом (кэш прогрет)
764
- done(r && (r.ok || r.status === 304))
773
+ // v1.1.1: для no-cors mode response.type === 'opaque', r.ok === false, но кэш прогрет
774
+ // v1.0.12: 304 Not Modified тоже считаем успехом
775
+ done(r && (r.ok || r.status === 304 || r.type === 'opaque'))
765
776
  })
766
777
  .catch(function () {
767
778
  done(false)