Skip to content

Instantly share code, notes, and snippets.

View deanhume's full-sized avatar
🎮
Gaming

Dean deanhume

🎮
Gaming
View GitHub Profile
@deanhume
deanhume / basic-share.js
Last active February 23, 2017 10:39
Basic web share dialog
// Check if the Web Share API is supported
if (navigator.share !== undefined) {
// Share the resource
navigator.share({
title: document.title,
url: shareUrl
}).then(() => console.log('Successful share'))
.catch((error) => console.log('Error sharing:', error));
}
@deanhume
deanhume / http2-html.html
Created October 24, 2016 12:42
HTTP/2 HTML file
<!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 -->
@deanhume
deanhume / http2.js
Last active March 16, 2018 11:28
HTTP/2 Server
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')
@deanhume
deanhume / h2-push-app.js
Last active October 24, 2016 12:48
HTTP/2 Server Push
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([
@deanhume
deanhume / speedindex-basic.js
Created September 19, 2016 13:29
A basic Speed Index example
<script src="rum-speedindex.js"></script>
<script async>
console.log(RUMSpeedIndex());
</script>
@deanhume
deanhume / speedindex.js
Created September 19, 2016 13:29
Track Speed Index RUM results using Google Analytics
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');
@deanhume
deanhume / imagebeast-config.js
Created August 23, 2016 12:38
imagebeast configuration
optimize({
useWebp: false,
useXr: true,
useSaveData: true,
useCache: false });
@deanhume
deanhume / service-worker-beast.js
Last active August 19, 2016 15:01
Register image beast
(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);
@deanhume
deanhume / register-sw.js
Created August 19, 2016 14:14
Register Service Worker
<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>
@deanhume
deanhume / offline-notification.js
Created August 2, 2016 09:17
Offline toast notifications
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) {