1const loadedProducts = new Map() 2 3export async function loadProduct(handle) { 4 if (!handle) { 5 throw new Error('The handle of the product is required before product can be loaded') 6 } 7 8 if (loadedProducts.has(handle)) { 9 return loadedProducts.get(handle) 10 } 11 12 const productJSON = await getProductJSON(`products/${handle}.js`) 13 loadedProducts.set(handle, productJSON) 14 return productJSON 15} 16 17export async function getProductJSON(endpoint) { 18 const response = await fetch(`${window.Shopify.routes.root}${endpoint}`) 19 20 if (!response.ok) { 21 throw new Error(`Failed to fetch data from endpoint: ${endpoint}`) 22 } 23 24 return response.json() 25}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.