This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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}', | |
| }, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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}', | |
| }, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Workbox with a custom handler to use IndexedDB for caching. | |
| workbox.routing.registerRoute( | |
| '/graphql', | |
| async ({event}) => staleWhileRevalidate(event), | |
| 'POST' | |
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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)); | |
| } | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| restaurants(type: French, stars: 3) { | |
| name | |
| type | |
| map | |
| stars | |
| } | |
| } |