Repository: GoogleChrome/sw-precache (js)

Issue:
url hashes count as cache misses
Like the title says.  `example.com` works, but `example.com#chapter2` counts as a cache miss and the page fails to load.

Is this a bug, or the intended behavior.  If it's intended, can we add a configuration option to strip hashes?  It could be done inside the `stripIgnoredUrlParameters` function.

Pull request description:
Remove the hash fragment the URL when determining if there's a match.
R: @addyosmani @gauntface 

Fixes #290 

Patch:
diff --git a/lib/functions.js b/lib/functions.js
index c485761..36d7ddf 100644
--- a/lib/functions.js
+++ b/lib/functions.js
@@ -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
diff --git a/service-worker.tmpl b/service-worker.tmpl
index 5d9b88e..69d1792 100644
--- a/service-worker.tmpl
+++ b/service-worker.tmpl
@@ -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);
 


Test patch:
diff --git a/test/test.js b/test/test.js
index f766133..e033baf 100644
--- a/test/test.js
+++ b/test/test.js
@@ -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();
   });
 });