@prefetchru/prefetch 1.1.0 → 1.1.1
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 +4 -4
- package/dist/prefetch.esm.min.js +2 -2
- package/dist/prefetch.min.js +2 -2
- package/package.json +1 -1
- package/prefetch.esm.js +16 -15
- package/prefetch.js +16 -15
- package/src/core.js +11 -9
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/@prefetchru/prefetch)
|
|
4
4
|
[](https://www.npmjs.com/package/@prefetchru/prefetch)
|
|
5
|
-
[](https://prefetch.ru)
|
|
6
6
|
[](LICENSE)
|
|
7
7
|
[](https://github.com/prefetch-ru/prefetch/releases)
|
|
8
8
|
[](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
|
-
- ~
|
|
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` | — | Разрешить внешние домены
|
|
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.
|
|
142
|
+
console.log(PrefetchRu.version) // "1.1.1"
|
|
143
143
|
|
|
144
144
|
// Программная предзагрузка URL
|
|
145
145
|
// ВАЖНО: URL проходит те же проверки, что и автоматические ссылки
|
package/dist/prefetch.esm.min.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* prefetch.ru v1.1.
|
|
2
|
+
* prefetch.ru v1.1.1 (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.1",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,E=65,L=80,x=50,T=!1,k=!1,O=!1,P=!1,A="none",S=!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){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&&(E=i)}p&&(L=Math.max(60,Math.min(E||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&&E<100&&(E=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});I&&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)},L)}}}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)},E);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!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 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){if("none"===n)m||!b?V(e,t):J(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($,{timeout:50})}}(e,n),r=!0}catch(e){}!S&&r||(m||!b?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.1",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};
|
package/dist/prefetch.min.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* prefetch.ru v1.1.
|
|
2
|
+
* prefetch.ru v1.1.1 - Мгновенная загрузка страниц
|
|
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.1",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,O=!1,k=!1,P=!1,S="none",A=!1,N=!1,C=!1,q=!1,I=!1,M=/(^|\/)(login|logout|auth|register|cart|basket|add|delete|remove)(\/|$|\.)/i,R=/\.(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,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(){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(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!==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}return("tilda"!==v||-1===r.indexOf("#popup:")&&-1===r.indexOf("#rec"))&&(!M.test(n)&&!R.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"!==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:u});Q(c,s,u)}}}function Q(e,t,n){if("none"===n)m||!b?V(e,t):J(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($,{timeout:50})}}(e,n),r=!0}catch(e){}!A&&r||(m||!b?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.1",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:!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
package/prefetch.esm.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* prefetch.ru v1.1.
|
|
2
|
+
* prefetch.ru v1.1.1 (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.
|
|
22
|
+
version: '1.1.1',
|
|
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
|
-
|
|
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)
|
|
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
|
-
|
|
418
|
+
// v1.1.1: убрано ограничение chromiumVer — Firefox и Safari тоже поддерживают cross-origin prefetch
|
|
420
419
|
}
|
|
421
420
|
|
|
422
421
|
// Query string
|
|
@@ -743,15 +742,16 @@ function createPrefetchCore(options) {
|
|
|
743
742
|
cache: 'force-cache',
|
|
744
743
|
// v1.0.13: для cross-origin: omit credentials, no-referrer (избегаем CORS preflight и утечки referrer)
|
|
745
744
|
credentials: isCrossOrigin ? 'omit' : 'same-origin',
|
|
746
|
-
// v1.
|
|
747
|
-
|
|
748
|
-
Accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'
|
|
749
|
-
}
|
|
745
|
+
// v1.1.1: для cross-origin используем no-cors mode (opaque response, но кэш прогревается)
|
|
746
|
+
mode: isCrossOrigin ? 'no-cors' : 'cors'
|
|
750
747
|
};
|
|
751
748
|
|
|
752
|
-
// v1.
|
|
749
|
+
// v1.1.1: headers только для same-origin (no-cors не позволяет кастомные headers)
|
|
753
750
|
if (!isCrossOrigin) {
|
|
754
|
-
opts.headers
|
|
751
|
+
opts.headers = {
|
|
752
|
+
Accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
|
|
753
|
+
Purpose: 'prefetch'
|
|
754
|
+
};
|
|
755
755
|
}
|
|
756
756
|
|
|
757
757
|
// v1.0.13: referrerPolicy для cross-origin (приватность)
|
|
@@ -764,8 +764,9 @@ function createPrefetchCore(options) {
|
|
|
764
764
|
try {
|
|
765
765
|
fetch(url, opts)
|
|
766
766
|
.then(function (r) {
|
|
767
|
-
// v1.
|
|
768
|
-
|
|
767
|
+
// v1.1.1: для no-cors mode response.type === 'opaque', r.ok === false, но кэш прогрет
|
|
768
|
+
// v1.0.12: 304 Not Modified тоже считаем успехом
|
|
769
|
+
done(r && (r.ok || r.status === 304 || r.type === 'opaque'));
|
|
769
770
|
})
|
|
770
771
|
.catch(function () {
|
|
771
772
|
done(false);
|
|
@@ -908,7 +909,7 @@ function createPrefetchCore(options) {
|
|
|
908
909
|
// Публичный API
|
|
909
910
|
var api = {
|
|
910
911
|
__prefetchRu: true,
|
|
911
|
-
version: '1.1.
|
|
912
|
+
version: '1.1.1',
|
|
912
913
|
preload: function (url) {
|
|
913
914
|
// v1.0.11: валидация URL + прогон через canPreload() (консистентность с авто-режимом)
|
|
914
915
|
if (!isValidPrefetchUrl(url)) return
|
package/prefetch.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* prefetch.ru v1.1.
|
|
2
|
+
* prefetch.ru v1.1.1 - Мгновенная загрузка страниц
|
|
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.
|
|
25
|
+
version: '1.1.1',
|
|
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
|
-
|
|
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)
|
|
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
|
-
|
|
421
|
+
// v1.1.1: убрано ограничение chromiumVer — Firefox и Safari тоже поддерживают cross-origin prefetch
|
|
423
422
|
}
|
|
424
423
|
|
|
425
424
|
// Query string
|
|
@@ -746,15 +745,16 @@
|
|
|
746
745
|
cache: 'force-cache',
|
|
747
746
|
// v1.0.13: для cross-origin: omit credentials, no-referrer (избегаем CORS preflight и утечки referrer)
|
|
748
747
|
credentials: isCrossOrigin ? 'omit' : 'same-origin',
|
|
749
|
-
// v1.
|
|
750
|
-
|
|
751
|
-
Accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'
|
|
752
|
-
}
|
|
748
|
+
// v1.1.1: для cross-origin используем no-cors mode (opaque response, но кэш прогревается)
|
|
749
|
+
mode: isCrossOrigin ? 'no-cors' : 'cors'
|
|
753
750
|
};
|
|
754
751
|
|
|
755
|
-
// v1.
|
|
752
|
+
// v1.1.1: headers только для same-origin (no-cors не позволяет кастомные headers)
|
|
756
753
|
if (!isCrossOrigin) {
|
|
757
|
-
opts.headers
|
|
754
|
+
opts.headers = {
|
|
755
|
+
Accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
|
|
756
|
+
Purpose: 'prefetch'
|
|
757
|
+
};
|
|
758
758
|
}
|
|
759
759
|
|
|
760
760
|
// v1.0.13: referrerPolicy для cross-origin (приватность)
|
|
@@ -767,8 +767,9 @@
|
|
|
767
767
|
try {
|
|
768
768
|
fetch(url, opts)
|
|
769
769
|
.then(function (r) {
|
|
770
|
-
// v1.
|
|
771
|
-
|
|
770
|
+
// v1.1.1: для no-cors mode response.type === 'opaque', r.ok === false, но кэш прогрет
|
|
771
|
+
// v1.0.12: 304 Not Modified тоже считаем успехом
|
|
772
|
+
done(r && (r.ok || r.status === 304 || r.type === 'opaque'));
|
|
772
773
|
})
|
|
773
774
|
.catch(function () {
|
|
774
775
|
done(false);
|
|
@@ -911,7 +912,7 @@
|
|
|
911
912
|
// Публичный API
|
|
912
913
|
var api = {
|
|
913
914
|
__prefetchRu: true,
|
|
914
|
-
version: '1.1.
|
|
915
|
+
version: '1.1.1',
|
|
915
916
|
preload: function (url) {
|
|
916
917
|
// v1.0.11: валидация URL + прогон через canPreload() (консистентность с авто-режимом)
|
|
917
918
|
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
|
-
|
|
415
|
+
// v1.1.1: убрано ограничение chromiumVer — Firefox и Safari тоже поддерживают cross-origin prefetch
|
|
416
416
|
}
|
|
417
417
|
|
|
418
418
|
// Query string
|
|
@@ -739,15 +739,16 @@ export function createPrefetchCore(options) {
|
|
|
739
739
|
cache: 'force-cache',
|
|
740
740
|
// v1.0.13: для cross-origin: omit credentials, no-referrer (избегаем CORS preflight и утечки referrer)
|
|
741
741
|
credentials: isCrossOrigin ? 'omit' : 'same-origin',
|
|
742
|
-
// v1.
|
|
743
|
-
|
|
744
|
-
Accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'
|
|
745
|
-
}
|
|
742
|
+
// v1.1.1: для cross-origin используем no-cors mode (opaque response, но кэш прогревается)
|
|
743
|
+
mode: isCrossOrigin ? 'no-cors' : 'cors'
|
|
746
744
|
}
|
|
747
745
|
|
|
748
|
-
// v1.
|
|
746
|
+
// v1.1.1: headers только для same-origin (no-cors не позволяет кастомные headers)
|
|
749
747
|
if (!isCrossOrigin) {
|
|
750
|
-
opts.headers
|
|
748
|
+
opts.headers = {
|
|
749
|
+
Accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
|
|
750
|
+
Purpose: 'prefetch'
|
|
751
|
+
}
|
|
751
752
|
}
|
|
752
753
|
|
|
753
754
|
// v1.0.13: referrerPolicy для cross-origin (приватность)
|
|
@@ -760,8 +761,9 @@ export function createPrefetchCore(options) {
|
|
|
760
761
|
try {
|
|
761
762
|
fetch(url, opts)
|
|
762
763
|
.then(function (r) {
|
|
763
|
-
// v1.
|
|
764
|
-
|
|
764
|
+
// v1.1.1: для no-cors mode response.type === 'opaque', r.ok === false, но кэш прогрет
|
|
765
|
+
// v1.0.12: 304 Not Modified тоже считаем успехом
|
|
766
|
+
done(r && (r.ok || r.status === 304 || r.type === 'opaque'))
|
|
765
767
|
})
|
|
766
768
|
.catch(function () {
|
|
767
769
|
done(false)
|