Skip to content
This repository has been archived by the owner on Jan 23, 2021. It is now read-only.

Commit

Permalink
Remove the hash fragment the URL when determining if there's a match. (
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffposnick authored May 4, 2017
1 parent eb782f6 commit da6d750
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 2 additions & 0 deletions lib/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ module.exports = {
stripIgnoredUrlParameters: function(originalUrl,
ignoreUrlParametersMatching) {
var url = new URL(originalUrl);
// Remove the hash; see https://github.com/GoogleChrome/sw-precache/issues/290
url.hash = '';

url.search = url.search.slice(1) // Exclude initial '?'
.split('&') // Split into an array of 'key=value' strings
Expand Down
4 changes: 2 additions & 2 deletions service-worker.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ self.addEventListener('fetch', function(event) {
// handlers a chance to handle the request if need be.
var shouldRespond;

// First, remove all the ignored parameter and see if we have that URL
// in our cache. If so, great! shouldRespond will be true.
// First, remove all the ignored parameters and hash fragment, and see if we
// have that URL in our cache. If so, great! shouldRespond will be true.
var url = stripIgnoredUrlParameters(event.request.url, ignoreUrlParametersMatching);
shouldRespond = urlsToCacheKeys.has(url);

Expand Down
4 changes: 2 additions & 2 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,9 +332,9 @@ describe('stripIgnoredUrlParameters', function() {
done();
});

it('should work when there\'s a hash fragment', function(done) {
it('should remove the hash fragment', function(done) {
var strippedUrl = externalFunctions.stripIgnoredUrlParameters(testUrl + '#hash', [/^t/, /^f/]);
assert.strictEqual(strippedUrl, 'http://example.com/index.html?one=1#hash');
assert.strictEqual(strippedUrl, 'http://example.com/index.html?one=1');
done();
});
});
Expand Down

0 comments on commit da6d750

Please sign in to comment.