serviceworker-cache-polyfill
Advanced tools
Comparing version 3.0.0 to 4.0.0
58
index.js
@@ -1,8 +0,37 @@ | ||
if (!Cache.prototype.add) { | ||
Cache.prototype.add = function add(request) { | ||
return this.addAll([request]); | ||
}; | ||
} | ||
/** | ||
* 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) { | ||
(function() { | ||
var nativeAddAll = Cache.prototype.addAll; | ||
var userAgent = navigator.userAgent.match(/(Firefox|Chrome)\/(\d+\.)/); | ||
// Has nice behavior of `var` which everyone hates | ||
if (userAgent) { | ||
var agent = userAgent[1]; | ||
var version = parseInt(userAgent[2]); | ||
} | ||
if ( | ||
nativeAddAll && (!userAgent || | ||
(agent === 'Firefox' && version >= 46) || | ||
(agent === 'Chrome' && version >= 50) | ||
) | ||
) { | ||
return; | ||
} | ||
Cache.prototype.addAll = function addAll(requests) { | ||
@@ -17,2 +46,3 @@ var cache = this; | ||
} | ||
NetworkError.prototype = Object.create(Error.prototype); | ||
@@ -22,3 +52,3 @@ | ||
if (arguments.length < 1) throw new TypeError(); | ||
// Simulate sequence<(Request or USVString)> binding: | ||
@@ -52,2 +82,10 @@ var sequence = []; | ||
}).then(function(responses) { | ||
// If some of the responses has not OK-eish status, | ||
// then whole operation should reject | ||
if (responses.some(function(response) { | ||
return !response.ok; | ||
})) { | ||
throw new NetworkError('Incorrect response status'); | ||
} | ||
// TODO: check that requests don't overwrite one another | ||
@@ -64,2 +102,6 @@ // (don't think this is possible to polyfill due to opaque responses) | ||
}; | ||
} | ||
Cache.prototype.add = function add(request) { | ||
return this.addAll([request]); | ||
}; | ||
}()); |
{ | ||
"name": "serviceworker-cache-polyfill", | ||
"version": "3.0.0", | ||
"version": "4.0.0", | ||
"description": "Cache polyfill for the ServiceWorker", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
# ServiceWorker cache polyfill | ||
This is a polyfill for the [ServiceWorker cache API](http://slightlyoff.github.io/ServiceWorker/spec/service_worker/#cache-storage-interface). | ||
[Obsolete](https://github.com/coonsta/cache-polyfill/issues/17#issuecomment-158628413) polyfill for the [ServiceWorker cache API](http://slightlyoff.github.io/ServiceWorker/spec/service_worker/#cache-storage-interface). Chrome 46 and Opera 33 support `addAll` now. | ||
## Usage | ||
Take [serviceworker-cache-polyfill.js](https://github.com/coonsta/cache-polyfill/blob/master/dist/serviceworker-cache-polyfill.js), then in your ServiceWorker script: | ||
Take [serviceworker-cache-polyfill.js](https://github.com/coonsta/cache-polyfill/blob/master/index.js), then in your ServiceWorker script: | ||
@@ -29,1 +29,13 @@ ```js | ||
``` | ||
## License | ||
Copyright 2015 Google, Inc. | ||
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you 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. | ||
Please note: this is not a Google product |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16628
5
87
41
1