Created
January 2, 2015 13:53
-
-
Save dannycroft/de3308131103a03c0e38 to your computer and use it in GitHub Desktop.
This file contains 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
// register the service worker | |
navigator.serviceWorker.register('/worker.js').then( | |
function(reg) { console.log('Installed successfully', reg) }, | |
function(err) { console.log('Worker installation failed', err) } | |
); | |
// ... worker.js | |
self.addEventListener('fetch', function(event) { | |
var requestURL = new URL(event.request); | |
// Intercept same origin /video/* requests | |
if (requestURL.origin == location.origin) { | |
if (/^\/video\//.test(requestURL.pathname)) { | |
// append the MD header, set value to NetInfo's downlinkMax: | |
// http://w3c.github.io/netinfo/#downlinkmax-attribute | |
event.respondWith( | |
fetch(event.request.url, { | |
headers: { 'MD': navigator.connection.downlinkMax } | |
}) | |
); | |
return; | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment