Skip to content

Instantly share code, notes, and snippets.

View Antoinebr's full-sized avatar
:octocat:
🔥

Antoinebr

:octocat:
🔥
View GitHub Profile

bit.ly/pwa-tips

Show an offline page when you have a cache miss

1 create an offline page and add the URL to the preache

const getContent  = async () => {

      const response = await fetch('https://jsonplaceholder.typicode.com/posts');

      // reponse is not correct
      if (!response.ok) throw new Error(`We received an invalid response  ${await response.text()}`);

 const reponseJson = await response.json(); 
@Antoinebr
Antoinebr / cors-amp-everywhere.html
Created April 9, 2019 19:42
cors-amp-everywhere.html
<amp-list src="https://cors-anywhere.herokuapp.com/https://www.energiedirect.nl/api/v1/search?maxContentLength=150&maxresults=5&q=home" single-item items="Results" width="900" height="100" layout="responsive" >
<template type="amp-mustache">
<p class="listitem">Dynamic DATA fetched with AJAX with amp-list 👍 : \{{Title}} </p>
</template>
</amp-list>

Edit Profile

nano ~/.bash_profile

Add this to the profile

getAmpCache(){
@Antoinebr
Antoinebr / refresh-amp-cache-with-node.md
Last active March 29, 2019 16:28
Refresh the AMP cache with the invalidation API
<script>
// more documentation : https://developers.google.com/analytics/devguides/collection/analyticsjs/ecommerce
ga('require', 'ecommerce'); // You have to require the ecommerce Addon
ga('ecommerce:addTransaction', {
'id': '{{orderId}}', // Transaction ID. Required.
'revenue': '{{orderToal}}', // Grand Total.
@Antoinebr
Antoinebr / workbox-strategies.js
Created December 12, 2018 14:48
workbox-strategies.js
/**
* Welcome to your Workbox-powered service worker!
*
* You'll need to register this file in your web app and you should
* disable HTTP caching for this file too.
* See https://goo.gl/nhQhGp
*
* The rest of the code is auto-generated. Please don't update this file
* directly; instead, make changes to your Workbox build configuration
* and re-run your build process.
@Antoinebr
Antoinebr / cacheOrNetwiork.js
Created December 10, 2018 15:20
cacheOrNetwiork.js
/**
* cacheOrNetwork
*
* Look for and returns an event request in the cache
* @param {eventRequest} event
* @param {string} cacheName
*/
const cacheOrNetwork = async (event, cacheName) => {
[...document.querySelectorAll('input')].forEach( input => {
input.setAttribute('value', `my type is ${input.getAttribute('type')}`);
input.setAttribute('style', `color:black; font-size:20px; font-weight:bold;`);
});