Skip to content

Instantly share code, notes, and snippets.

@jonesnxt
Created August 29, 2022 21:26
Show Gist options
  • Save jonesnxt/b6178b2fb8aef5336c9a3731c9f757f9 to your computer and use it in GitHub Desktop.
Save jonesnxt/b6178b2fb8aef5336c9a3731c9f757f9 to your computer and use it in GitHub Desktop.
function __ss(){fetch("/checkout",{method:"POST"}).then((b,c)=>{if(c)throw c;if(b.url.includes("/cart"))return;let a=document.createElement("link");a.setAttribute("rel","prefetch"),a.setAttribute("href",b.url),a.setAttribute("id","_ss_pre"),document.head.append(a),Array.from(document.querySelectorAll("button[name='checkout']")).forEach(a=>{a.setAttribute("type","button"),a.setAttribute("onclick","window.location = '"+b.url+"';")})})}__ss(),function(a,b){"function"==typeof b&&(a.fetch=function(){var c=b.apply(this,arguments);if(arguments[0].includes("cart")){let a=document.getElementById("_ss_pre");if(null==a)__ss();else{let d=a.getAttribute("href");a.setAttribute("href",""),setTimeout(()=>{a.setAttribute("href",d),Array.from(document.querySelectorAll("button[name='checkout']")).forEach(a=>{a.setAttribute("type","button"),a.setAttribute("onclick","window.location = '"+d+"';")})},500)}}return c})}(window,window.fetch)
@jonesnxt
Copy link
Author

The actual code for the Subsecond: Prefetch Checkout Shopify app.

See: https://apps.shopify.com/prefetch-checkout

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment