Skip to content

Instantly share code, notes, and snippets.

@gokulkrishh
Last active July 21, 2020 14:38
Show Gist options
  • Save gokulkrishh/1b47bad975eed2f50f66 to your computer and use it in GitHub Desktop.
Save gokulkrishh/1b47bad975eed2f50f66 to your computer and use it in GitHub Desktop.

Revisions

  1. gokulkrishh revised this gist Feb 11, 2016. No changes.
  2. gokulkrishh revised this gist Feb 11, 2016. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion sw.js
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,4 @@
    //After install, fetch event is triggered for every page request

    self.addEventListener("fetch", function (event) {
    console.log("Request -->", event.request.url);

  3. gokulkrishh revised this gist Feb 11, 2016. No changes.
  4. gokulkrishh revised this gist Feb 11, 2016. No changes.
  5. gokulkrishh revised this gist Feb 11, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion sw.js
    Original file line number Diff line number Diff line change
    @@ -7,7 +7,7 @@ self.addEventListener("fetch", function (event) {
    event.respondWith(
    caches.match(event.request) //To match current request with cached request it
    .then(function(response) {
    //If response found return it else fetch again.
    //If response found return it, else fetch again.
    return response || fetch(event.request);
    })
    .catch(function(error) {
  6. gokulkrishh revised this gist Feb 11, 2016. No changes.
  7. gokulkrishh created this gist Feb 11, 2016.
    17 changes: 17 additions & 0 deletions sw.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    //After install, fetch event is triggered for every page request

    self.addEventListener("fetch", function (event) {
    console.log("Request -->", event.request.url);

    //To tell browser to evaluate the result of event
    event.respondWith(
    caches.match(event.request) //To match current request with cached request it
    .then(function(response) {
    //If response found return it else fetch again.
    return response || fetch(event.request);
    })
    .catch(function(error) {
    console.error("Error: ", error);
    })
    );
    });