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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<title>HTTP2 Push Demo</title> | |
</head> | |
<body> | |
<h1>HTTP2 Push FTW!</h1> | |
<img src="./images/image.jpg" alt="snowboarder" /> | |
<!-- Scripts --> |
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
const spdy = require('spdy'); | |
const express = require('express'); | |
const fs = require('mz/fs'); | |
const app = express(); | |
app.use(express.static('public')); | |
app.get('/home', (req, res) => { | |
fs.readFile('home.html') |
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
const spdy = require('spdy'); | |
const express = require('express'); | |
const fs = require('mz/fs'); | |
const app = express(); | |
app.use(express.static('public')); | |
app.get('/home', (req, res) => { | |
Promise.all([ |
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
<script src="rum-speedindex.js"></script> | |
<script async> | |
console.log(RUMSpeedIndex()); | |
</script> |
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
var speedIndexResult = RUMSpeedIndex(); // Calculate the speed index for this page | |
document.getElementById('speedIndexResult').innerHTML = Math.round(speedIndexResult); // Display it on the page | |
// Include the GA script | |
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ | |
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), | |
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) | |
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga'); | |
ga('create', 'UA-84298674-1', 'auto'); |
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
optimize({ | |
useWebp: false, | |
useXr: true, | |
useSaveData: true, | |
useCache: false }); |
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
(global => { | |
'use strict'; | |
importScripts('./imagebeast.min.js'); | |
optimize({ useWebp: false, useXr: true, useSaveData: true, useCache: true }); | |
// Ensure that our service worker takes control of the page as soon as possible. | |
global.addEventListener('install', event => event.waitUntil(global.skipWaiting())); | |
global.addEventListener('activate', event => event.waitUntil(global.clients.claim())); | |
})(self); |
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
<script> | |
// Register the service worker | |
if ('serviceWorker' in navigator) { | |
navigator.serviceWorker.register('./service-worker.js').then(function(registration) { | |
// Registration was successful | |
console.log('ServiceWorker registration successful with scope: ', registration.scope); | |
}) | |
} | |
</script> |
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
function showOfflineNotification() { | |
if ('serviceWorker' in navigator) { | |
// Open the cache and check if we have this page saved | |
caches.open('beer-data').then(function(cache) { | |
var urlToCheck = 'https://deanhume.github.io/beer' + createStyleUrl(styleId, pageId, false); | |
cache.match(urlToCheck) | |
.then(function(response) { | |
if (response == undefined){ return; } // return if we found nothing | |
// We found the resource in cache | |
if (response.ok && localStorage.getItem(urlToCheck) === null) { |