Skip to content

Instantly share code, notes, and snippets.

Avatar

Jonathan Chen jonchenn

View GitHub Profile
View Bosley AMP-form test - success
fetch(url, {
method: 'POST',
headers: {
'AMP-Same-Origin': 'true',
'Accept': 'application/json',
'Content-Type': 'multipart/form-data; boundary=----WebKitFormBoundaryzCA5AbNQoBPgNVsS',
'Origin': 'http://qa.bosley.com',
'Referer': 'http://qa.bosley.com/lpamp/gbh1/?amp',
'User-Agent': 'Mozilla/5.0 (Linux; Android 8.0; Pixel 2 Build/OPD3.170816.012) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Mobile Safari/537.36}',
},
View Bosley AMP-form test - 404
fetch(url, {
method: 'POST',
headers: {
'AMP-Same-Origin': 'true',
'Accept': 'application/json',
'Content-Type': 'multipart/form-data; boundary=----WebKitFormBoundaryzCA5AbNQoBPgNVsS',
'Origin': 'http://qa.bosley.com',
'Referer': 'http://qa.bosley.com/lpamp/gbh1/?amp',
'User-Agent': 'Mozilla/5.0 (Linux; Android 8.0; Pixel 2 Build/OPD3.170816.012) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Mobile Safari/537.36}',
},
View sw-graphql-4.js
data = await idbKeyval.get(id, store);
if (!data) return null;
// Check cache max age.
let cacheControl = request.headers.get('Cache-Control');
let maxAge = cacheControl ? parseInt(cacheControl.split('=')[1]) : 3600;
if (Date.now() - data.timestamp > maxAge * 1000) {
return null; // Invalidate the cache data.
}
View sw-graphql-3.js
// Workbox with a custom handler to use IndexedDB for caching.
workbox.routing.registerRoute(
'/graphql',
async ({event}) => staleWhileRevalidate(event),
'POST'
);
View sw-graphql-2.js
self.addEventListener('fetch', async (event) => {
if (event.request.method === 'POST') {
// Respond with cached data and update from network in the background.
event.respondWith(staleWhileRevalidate(event));
}
});
View sw-graphql-1.js
{
restaurants(type: French, stars: 3) {
name
type
map
stars
}
}