Created
April 21, 2016 08:20
-
-
Save stefanjudis/3ed41763fdffeb6c4b9a51e9fc9b437f 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
var SLOW_TIME = 3000; | |
this.addEventListener( 'install', function () { | |
console.log('Installed service worker'); | |
} ); | |
this.addEventListener( 'fetch', function(event) { | |
var url = event.request.url; | |
if ( url.indexOf( 'blocking' ) === -1) { | |
return; | |
} | |
var promise = Promise.race( [ | |
new Promise( ( resolve, reject) => setTimeout( | |
() => reject( new Response( 'Request killed!' ) ), | |
SLOW_TIME | |
) ), | |
fetch( event.request ), | |
] ); | |
event.respondWith( promise ); | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
console.log('Hello from sw.js');