@prefetchru/prefetch 1.0.4 → 1.0.5
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 +1 -1
- package/dist/prefetch.min.js +2 -2
- package/package.json +1 -1
- package/prefetch.js +10 -7
package/README.md
CHANGED
|
@@ -98,7 +98,7 @@ import '@prefetchru/prefetch'
|
|
|
98
98
|
// Доступен объект window.Prefetch после загрузки скрипта
|
|
99
99
|
|
|
100
100
|
// Версия библиотеки
|
|
101
|
-
console.log(Prefetch.version) // "1.0.
|
|
101
|
+
console.log(Prefetch.version) // "1.0.5"
|
|
102
102
|
|
|
103
103
|
// Программная предзагрузка URL
|
|
104
104
|
Prefetch.preload('/catalog/product-123')
|
package/dist/prefetch.min.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* prefetch.ru v1.0.
|
|
2
|
+
* prefetch.ru v1.0.5 - Мгновенная загрузка страниц
|
|
3
3
|
* © 2026 Сергей Макаров | MIT License
|
|
4
4
|
* https://prefetch.ru | https://github.com/prefetch-ru
|
|
5
5
|
*/
|
|
6
|
-
!function(){"use strict";var e=new Set,t=new WeakMap,n=0,r=0,i=null,o=!1,a=!1,c=null,u=null,s=!1,l=null,d=null,f=!1,m=65,
|
|
6
|
+
!function(){"use strict";var e=new Set,t=new WeakMap,n=0,r=0,i=null,o=!1,a=!1,c=null,u=null,s=!1,l=null,d=null,f=!1,m=65,h=80,p=50,v=!1,g=!1,x=!1,w=!1,y="none",L=!1,b=!1,E=!1,T=!1;function O(){var e=document.body;if(e){u=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(v="prefetchAllowQueryString"in t||"instantAllowQueryString"in t,g="prefetchAllowExternalLinks"in t||"instantAllowExternalLinks"in t,x="prefetchWhitelist"in t||"instantWhitelist"in t,t.prefetchNonce&&(d=t.prefetchNonce),!d&&t.instantNonce&&(d=t.instantNonce),!a&&("prefetchSpecrules"in t||"instantSpecrules"in t)&&HTMLScriptElement.supports&&HTMLScriptElement.supports("speculationrules")){var n=t.prefetchSpecrules||t.instantSpecrules;"prerender"===n?(y="prerender",w=!0):"no"!==n&&(y="prefetch",w=!0)}L="prefetchPrerenderAll"in t||"instantPrerenderAll"in t;var r=t.prefetchIntensity||t.instantIntensity;if("mousedown"===r)b=!0;else if("viewport"===r||"viewport-all"===r)("viewport-all"===r||o&&S())&&(E=!0);else if(r){var i=parseInt(r,10);!isNaN(i)&&i>=0&&(m=i)}o&&(h=Math.max(60,Math.min(m||0,150))),(T="prefetchObserveDom"in t)||"bitrix"!==u&&"tilda"!==u||(T=!0),"tilda"===u&&m<100&&(m=100);var c={capture:!0,passive:!0};if(document.addEventListener("touchstart",k,c),b?document.addEventListener("mousedown",M,c):document.addEventListener("mouseover",N,c),E)(window.requestIdleCallback||function(e){setTimeout(e,1)})(R,{timeout:1500});T&&function(){if(z)return;(z=new MutationObserver(function(e){e.some(function(e){return Array.from(e.addedNodes).some(function(e){return 1===e.nodeType&&("A"===e.tagName||e.querySelectorAll&&e.querySelectorAll("a").length)})})&&B&&(clearTimeout(H),H=setTimeout(U,100))})).observe(document.body,{childList:!0,subtree:!0})}()}}function S(){return!s&&("slow-2g"!==l&&"2g"!==l)}function A(e){return e?(e.nodeType&&1!==e.nodeType&&(e=e.parentElement),e&&"function"==typeof e.closest?e.closest("a"):null):null}function k(e){n=e.timeStamp||Date.now();var t=A(e.target);if(C(t)){r&&(clearTimeout(r),r=0),i&&(document.removeEventListener("touchmove",i,!0),document.removeEventListener("scroll",i,!0),i=null);var o=!1;i=function(){o=!0,r&&(clearTimeout(r),r=0),document.removeEventListener("touchmove",i,!0),document.removeEventListener("scroll",i,!0),i=null},document.addEventListener("touchmove",i,{capture:!0,passive:!0,once:!0}),document.addEventListener("scroll",i,{capture:!0,passive:!0,once:!0}),r=setTimeout(function(){i&&(document.removeEventListener("touchmove",i,!0),document.removeEventListener("scroll",i,!0),i=null),r=0,o||W(t.href,t)},h)}}function N(e){if(!(n&&e.timeStamp&&e.timeStamp-n<2500)){var r=A(e.target);if(C(r)){r.addEventListener("mouseout",P,{passive:!0,once:!0});var i=setTimeout(function(){W(r.href,r),t.delete(r)},m);t.set(r,i)}}}function P(e){var n=A(e.target);if(n&&(!e.relatedTarget||!e.relatedTarget.closest||n!==e.relatedTarget.closest("a"))){var r=t.get(n);r&&(clearTimeout(r),t.delete(n))}}function M(e){if(!("number"==typeof e.button&&2===e.button||n&&e.timeStamp&&e.timeStamp-n<2500)){var t=A(e.target);C(t)&&W(t.href,t)}}function C(t){if(!t||!t.href)return!1;if(t.target&&"_self"!==t.target)return!1;if(t.hasAttribute("download"))return!1;if("noPrefetch"in t.dataset||"prefetchNo"in t.dataset)return!1;if(x&&!("prefetch"in t.dataset)&&!("instant"in t.dataset))return!1;if("http:"!==t.protocol&&"https:"!==t.protocol)return!1;if("http:"===t.protocol&&"https:"===location.protocol)return!1;if(t.origin!==location.origin){if(!g&&!("prefetch"in t.dataset)&&!("instant"in t.dataset))return!1;if(!c)return!1}if(t.search&&!v&&!("prefetch"in t.dataset)&&!("instant"in t.dataset))return!1;if(t.hash&&t.pathname+t.search===location.pathname+location.search)return!1;var n=I(t.href);return!e.has(n)&&(!!function(e){var t=e.href;if("bitrix"===u||"bitrix24"===u){if(-1!==t.indexOf("/bitrix/")||-1!==t.indexOf("sessid="))return!1;if(e.classList.contains("bx-ajax"))return!1}if("tilda"===u&&(-1!==t.indexOf("#popup:")||-1!==t.indexOf("#rec")))return!1;return-1===t.indexOf("/login")&&-1===t.indexOf("/logout")&&-1===t.indexOf("/auth")&&-1===t.indexOf("/register")&&-1===t.indexOf("/cart")&&-1===t.indexOf("/basket")&&-1===t.indexOf("/add")&&-1===t.indexOf("/delete")&&-1===t.indexOf("/remove")&&!/\.(pdf|doc|docx|xls|xlsx|zip|rar|exe)($|\?)/.test(t)}(t)&&!!function(e){var t=e.href,n=e.className||"",r="";try{r=new URL(t,location.href).hostname}catch(e){r=""}return-1===n.indexOf("ym-")&&("mc.yandex.ru"!==r&&"metrika.yandex.ru"!==r&&(-1===n.indexOf("ga-")&&-1===n.indexOf("gtm-")&&("google-analytics.com"!==r&&!r.endsWith(".google-analytics.com")&&("googletagmanager.com"!==r&&!r.endsWith(".googletagmanager.com")&&(-1===n.indexOf("piwik")&&-1===n.indexOf("matomo")&&("matomo.org"!==r&&!r.endsWith(".matomo.org")&&"piwik.org"!==r&&!r.endsWith(".piwik.org")))))))}(t))}function I(e){try{var t=new URL(e,location.href);return t.origin+t.pathname+t.search}catch(t){return e}}function W(t,n){if(S()){var r=function(e){try{var t=new URL(e,location.href);return t.hash="",t.href}catch(t){return e}}(t),i=I(r);if(!e.has(i)){e.size>=p&&e.delete(e.values().next().value),e.add(i);var o=function(e){return w&&"none"!==y?"prerender"!==y?y:L||x||e&&e.dataset&&("prefetchPrerender"in e.dataset||"instantPrerender"in e.dataset)?"prerender":"prefetch":"none"}(n);if("none"!==o)return function(e,t){var n=document.head;if(!n)return;var r=document.createElement("script");r.type="speculationrules",d&&(r.nonce=d);var i={};i[t]=[{source:"list",urls:[e]}],r.textContent=JSON.stringify(i),n.appendChild(r)}(r,o),void(a||!f?D(r,i):q(r,i));a||!f?D(r,i):q(r,i)}}}function q(t,n){var r=document.head;if(r){var i=document.createElement("link");i.rel="prefetch",i.href=t,i.as="document";try{i.fetchPriority="low"}catch(e){}i.onerror=function(){e.delete(n)},r.appendChild(i)}}function D(t,n){if("function"==typeof fetch){var r=null,i=0;"undefined"!=typeof AbortController&&(r=new AbortController,i=setTimeout(function(){try{r.abort()}catch(e){}},5e3));var o={method:"GET",credentials:"same-origin",cache:"force-cache",headers:{Purpose:"prefetch"}};r&&(o.signal=r.signal);try{fetch(t,o).then(function(t){i&&clearTimeout(i),t&&t.ok||e.delete(n)}).catch(function(){i&&clearTimeout(i),e.delete(n)})}catch(t){i&&clearTimeout(i),e.delete(n)}}}!function(){try{var e=document.currentScript;e&&e.nonce&&(d=e.nonce)}catch(e){}try{var t=document.createElement("link");t.relList&&"function"==typeof t.relList.supports&&(f=t.relList.supports("prefetch"))}catch(e){}var n=navigator.userAgent;a=/iPad|iPhone/.test(n)||"MacIntel"===navigator.platform&&navigator.maxTouchPoints>1;var r=/Android/.test(n);(o=(a||r)&&Math.min(screen.width,screen.height)<768)&&(p=20);var i=n.match(/Chrome\/(\d+)/);i&&(c=parseInt(i[1],10));var u=navigator.connection;u&&(l=u.effectiveType,s=u.saveData||!1),"loading"===document.readyState?document.addEventListener("DOMContentLoaded",O):O()}();var B=null;function R(){B||(B=new IntersectionObserver(function(e){e.forEach(function(e){e.isIntersecting&&(B.unobserve(e.target),C(e.target)&&W(e.target.href,e.target))})},{rootMargin:o?"100px":"200px"}),U())}function U(){B&&document.querySelectorAll("a").forEach(function(e){C(e)&&B.observe(e)})}var z=null,H=null;window.Prefetch={version:"1.0.5",preload:function(e){W(e)}}}();
|
package/package.json
CHANGED
package/prefetch.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* prefetch.ru v1.0.
|
|
2
|
+
* prefetch.ru v1.0.5 - Мгновенная загрузка страниц
|
|
3
3
|
* © 2026 Сергей Макаров | MIT License
|
|
4
4
|
* https://prefetch.ru | https://github.com/prefetch-ru
|
|
5
5
|
*/
|
|
@@ -339,16 +339,19 @@
|
|
|
339
339
|
var href = a.href
|
|
340
340
|
var cls = a.className || ''
|
|
341
341
|
|
|
342
|
+
// Извлекаем hostname для проверки доменов аналитики
|
|
343
|
+
var host = ''
|
|
344
|
+
try { host = new URL(href, location.href).hostname } catch (e) { host = '' }
|
|
345
|
+
|
|
342
346
|
if (cls.indexOf('ym-') !== -1) return false
|
|
343
|
-
if (
|
|
344
|
-
if (href.indexOf('metrika.yandex') !== -1) return false
|
|
347
|
+
if (host === 'mc.yandex.ru' || host === 'metrika.yandex.ru') return false
|
|
345
348
|
|
|
346
349
|
if (cls.indexOf('ga-') !== -1 || cls.indexOf('gtm-') !== -1) return false
|
|
347
|
-
if (
|
|
348
|
-
if (
|
|
350
|
+
if (host === 'google-analytics.com' || host.endsWith('.google-analytics.com')) return false
|
|
351
|
+
if (host === 'googletagmanager.com' || host.endsWith('.googletagmanager.com')) return false
|
|
349
352
|
|
|
350
353
|
if (cls.indexOf('piwik') !== -1 || cls.indexOf('matomo') !== -1) return false
|
|
351
|
-
if (
|
|
354
|
+
if (host === 'matomo.org' || host.endsWith('.matomo.org') || host === 'piwik.org' || host.endsWith('.piwik.org')) return false
|
|
352
355
|
|
|
353
356
|
return true
|
|
354
357
|
}
|
|
@@ -532,7 +535,7 @@
|
|
|
532
535
|
|
|
533
536
|
// Минимальный публичный API
|
|
534
537
|
window.Prefetch = {
|
|
535
|
-
version: '1.0.
|
|
538
|
+
version: '1.0.5',
|
|
536
539
|
preload: function (url) { preload(url) }
|
|
537
540
|
}
|
|
538
541
|
})()
|