From 0d6e8225bdbf68025025ece003311fc9209ddc1a Mon Sep 17 00:00:00 2001 From: shaun554 Date: Thu, 17 Dec 2015 16:48:09 +0100 Subject: [PATCH] Remove the ServiceWorker cache polyfill This has been deprecated, see coonsta/cache-polyfill#17 Closes #22 --- FILE-APPENDIX.md | 2 - README.md | 2 +- js/app.js | 1 - serviceworker-cache-polyfill.js | 72 --------------------------------- serviceworker.js | 2 - 5 files changed, 1 insertion(+), 78 deletions(-) delete mode 100644 serviceworker-cache-polyfill.js diff --git a/FILE-APPENDIX.md b/FILE-APPENDIX.md index ea6374c..adda5d8 100644 --- a/FILE-APPENDIX.md +++ b/FILE-APPENDIX.md @@ -27,5 +27,3 @@ * `server.js`: The development server, which allows us to go to `localhost:3000` and see the application live. Also makes hot-reloading work. * `serviceworker.js`: The script that tells the serviceworker how to cache our files. - - * `serviceworker-cache-polyfill.js`: A polyfill for the `ServiceWorker` cache, which isn't yet fully supported everywhere. (See [https://jakearchibald.com/2014/using-serviceworker-today/](here) for more information) diff --git a/README.md b/README.md index 40870ee..5b08b32 100644 --- a/README.md +++ b/README.md @@ -106,7 +106,7 @@ To cache a file, add it to the `urlsToCache` variable in the [`serviceworker.js` **Careful** about removing this, as there is no real downside to having your application available when the users network connection isn't perfect. -To remove offline capability, delete [`serviceworker.js`](serviceworker.js) and [`serviceworker-cache-polyfill.js`](serviceworker-cache-polyfill.js), don't import them in the [`app.js`](js/app.js), remove `AppCachePlugin` in [`makewebpackconfig.js`](makewebpackconfig.js) and remove the `manifest` attribute of the `` tag in [`index.html`](index.html). +To remove offline capability, delete [`serviceworker.js`](serviceworker.js), remove the import in [`app.js`](js/app.js), remove `AppCachePlugin` in [`makewebpackconfig.js`](makewebpackconfig.js) and remove the `manifest` attribute of the `` tag in [`index.html`](index.html). ### Add To Homescreen diff --git a/js/app.js b/js/app.js index 96d8231..d1fdccd 100644 --- a/js/app.js +++ b/js/app.js @@ -9,7 +9,6 @@ // Load the ServiceWorker, the Cache polyfill, the manifest.json file and the .htaccess file import 'file?name=[name].[ext]!../serviceworker.js'; -import 'file?name=[name].[ext]!../serviceworker-cache-polyfill.js'; import 'file?name=[name].[ext]!../manifest.json'; import 'file?name=[name].[ext]!../.htaccess'; diff --git a/serviceworker-cache-polyfill.js b/serviceworker-cache-polyfill.js deleted file mode 100644 index db862e5..0000000 --- a/serviceworker-cache-polyfill.js +++ /dev/null @@ -1,72 +0,0 @@ -/** - * Copyright 2015 Google Inc. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ - -if (!Cache.prototype.addAll) { - Cache.prototype.addAll = function addAll(requests) { - var cache = this; - - // Since DOMExceptions are not constructable: - function NetworkError(message) { - this.name = 'NetworkError'; - this.code = 19; - this.message = message; - } - NetworkError.prototype = Object.create(Error.prototype); - - return Promise.resolve().then(function() { - if (arguments.length < 1) throw new TypeError(); - - // Simulate sequence<(Request or USVString)> binding: - var sequence = []; - - requests = requests.map(function(request) { - if (request instanceof Request) { - return request; - } - else { - return String(request); // may throw TypeError - } - }); - - return Promise.all( - requests.map(function(request) { - if (typeof request === 'string') { - request = new Request(request); - } - - var scheme = new URL(request.url).protocol; - - if (scheme !== 'http:' && scheme !== 'https:') { - throw new NetworkError("Invalid scheme"); - } - - return fetch(request.clone()); - }) - ); - }).then(function(responses) { - // TODO: check that requests don't overwrite one another - // (don't think this is possible to polyfill due to opaque responses) - return Promise.all( - responses.map(function(response, i) { - return cache.put(requests[i], response); - }) - ); - }).then(function() { - return undefined; - }); - }; -} \ No newline at end of file diff --git a/serviceworker.js b/serviceworker.js index 96d5898..43a8b5c 100644 --- a/serviceworker.js +++ b/serviceworker.js @@ -1,5 +1,3 @@ -importScripts('serviceworker-cache-polyfill.js'); - var CACHE_NAME = 'react-boilerplate-cache-v1'; // The files we want to cache var urlsToCache = [