Skip to content

Instantly share code, notes, and snippets.

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

Antoinebr

:octocat:
🔥
  • Fastly
  • Paris / Rennes
View GitHub Profile
@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.
<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 / refresh-amp-cache-with-node.md
Last active March 29, 2019 16:28
Refresh the AMP cache with the invalidation API

Edit Profile

nano ~/.bash_profile

Add this to the profile

getAmpCache(){
@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>
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(); 

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

@Antoinebr
Antoinebr / event.js
Created July 30, 2019 18:37
event.js
gtag('event', 'purchase', {
"transaction_id": "24.031608523954162",
"affiliation": "Google online store",
"value": 23.07,
"currency": "USD",
"tax": 1.24,
"shipping": 0,
"items": [
{
"id": "P12345",
@Antoinebr
Antoinebr / wpt-script.md
Last active May 7, 2021 14:12
wpt-script.md

An example of a webPageTest script

setEventName    Go to HomePage

navigate    https://monbraceletnato.fr

setEventName    Display category page

execAndWait document.querySelectorAll('.home-cta a')[1].click();

Detect standalone IOS

// Detects if device is on iOS 
const isIos = () => {
  const userAgent = window.navigator.userAgent.toLowerCase();
  return /iphone|ipad|ipod/.test( userAgent );
}
// Detects if device is in standalone mode