Skip to content
This repository has been archived by the owner on May 17, 2019. It is now read-only.

Add polyfill for location.origin #97

Merged
merged 1 commit into from
Feb 6, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function getOutdatedKeys(cache, cacheablePaths) {
return cache.keys().then(requests =>
requests.filter(request => {
return !cacheablePaths.find(key => {
return location.origin + String(key) === request.url;
return origin() + String(key) === request.url;
});
})
);
Expand Down Expand Up @@ -109,3 +109,8 @@ function responseIsHtml(response) {
const contentType = response.headers.get('content-type');
return contentType && contentType.indexOf('html') > -1;
}

function origin() {
const {origin, protocol, hostname, port} = location;
return origin || `${protocol}'//'${hostname}${port ? ':' + port : ''}`;
}