mykiwi/mykiwi.blogpublic Fork 0
1ce0eef91b735b1a8e1c1a3977d48214117e2921
Commits
Clone
git clone https://git.rickub.com/mykiwi/mykiwi.blog.git
git clone ssh://git@rickub.com/mykiwi/mykiwi.blog.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

hx-preload.min.js · 1 line · 1.7 KBJavaScript Blame HistoryRaw
Smooth page transitions with htmx boost, morph, and preload ca8b900 Romain Gautier 18h ago1(()=>{let e;htmx.registerExtension("preload",{init:t=>{e=t},htmx_after_init:t=>{!function(t){let r=e.attributeValue(t,"hx-preload");if(null==r&&!t._htmx?.boosted)return;let o=[],a=5e3;if(r){let t=e.parseTriggerSpecs(r);if(0===t.length)return;for(const e of t)o.push(e.name),e.timeout&&(a=htmx.parseInterval(e.timeout))}else{let r=t._htmx?.boosted&&"A"===t.tagName,l=null!=e.attributeValue(t,"hx-get");if(!r&&!l)return;if(r&&!1===htmx.config?.preload?.autoBoost)return;htmx.config?.preload?.boostTimeout&&(a=htmx.parseInterval(htmx.config.preload.boostTimeout)),o.push(htmx.config?.preload?.boostEvent||"mousedown"),o.push("touchstart")}let l=async r=>{let{method:o}=e.determineMethodAndAction(t,r);if("GET"!==o)return;if(t._htmx?.preload)return;let l=e.createRequestContext(t,r),n=t.form||t.closest("form"),i=e.collectFormData(t,n,r.submitter),h=e.getAttributeObject(t,"hx-vals",e=>{for(let t in e)i.set(t,e[t])});h&&await h;let s=l.request.action.replace?.(/#.*$/,""),m=new URLSearchParams(i);m.size&&(s+=(/\?/.test(s)?"&":"?")+m);let p=new URL(s,location.href);t._htmx.preload={prefetch:fetch(s,l.request),action:p.origin===location.origin?p.pathname+p.search:p.href,expiresAt:Date.now()+a};try{await t._htmx.preload.prefetch}catch(e){delete t._htmx.preload}};for(let e of o)t.addEventListener(e,l,{passive:!0});t._htmx.preloadListener=l,t._htmx.preloadEvents=o}(t)},htmx_before_request:(e,t)=>{let{ctx:r}=t;if(e._htmx?.preload&&e._htmx.preload.action===r.request.action&&Date.now()<e._htmx.preload.expiresAt){let t=e._htmx.preload.prefetch;r.fetch=()=>t,delete e._htmx.preload}else e._htmx&&delete e._htmx.preload},htmx_before_cleanup:e=>{if(e._htmx?.preloadListener)for(let t of e._htmx.preloadEvents)e.removeEventListener(t,e._htmx.preloadListener)}})})();