Skip to content

Commit 220a809

Browse files
committed
support offline mode
1 parent 93d05dd commit 220a809

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

public/js/sw-page-transition.js

+11-5
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ const transition = (function() {
8787
return Promise.resolve(null);
8888
}
8989
// Returned the transition page
90-
this.log('fetchWithPageTransition: return transition page');
9190
return this.fetchTransitionPage(request, transitionPage);
9291
}
9392

@@ -105,13 +104,20 @@ const transition = (function() {
105104
return caches.match(new Request(transitionPage))
106105
.then(response => {
107106
if (!response) {
108-
this.log('fetchWithPageTransition: loading page not found in cache');
107+
this.log('fetchTransitionPage: loading page not found in cache');
109108
return Promise.resolve(null);
110109
}
110+
this.log('fetchTransitionPage: return transition page');
111111
// Fetch the actual page and notify transition page when it's ready
112-
this.openCache().then(cache =>
113-
cache.add(request).then(() => this.notifyListeners(request.url))
114-
);
112+
this.openCache()
113+
.then(cache => cache.add(request)
114+
.then(() => this.notifyListeners(request.url))
115+
.catch(() => {
116+
// offline
117+
console.log('handling offline case');
118+
this.notifyListeners(request.url);
119+
})
120+
);
115121
return Promise.resolve(response);
116122
});
117123
}

0 commit comments

Comments
 (0)