Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
sw-appcache-behavior
Advanced tools
A service worker implementation of the behavior defined in a page's App Cache manifest.
A service worker implementation of the behavior defined in a page's App Cache manifest.
npm install --save-dev sw-appcache-behavior
Browse sample source code in the demo directory, or try it out directly.
packages/sw-appcache-behavior/src/appcache-behavior-import.js:514-527
goog.appCacheBehavior.fetch
is the main entry point to the library
from within service worker code.
The goal of the library is to provide equivalent behavior to AppCache whenever possible. The one difference in how this library behaves compared to a native AppCache implementation is that its client-side code will attempt to fetch a fresh AppCache manifest once any cached version is older than 24 hours. This works around a major pitfall in the native AppCache implementation.
Important
In addition to calling goog.appCacheBehavior.fetch()
from within your
service worker, you must add the following to each HTML document that
contains an App Cache Manifest:
<script src="path/to/client-runtime.js"
data-service-worker="service-worker.js">
</script>
(The data-service-worker
attribute is optional. If provided, it will
automatically call
navigator.serviceWorker.register()
for you.)
Once you've added <script src="path/to/client-runtime.js"></script>
to
your HTML pages, you can use goog.appCacheBehavior.fetch
within your
service worker script to get a Response
suitable for passing to
FetchEvent.respondWidth()
:
// Import the library into the service worker global scope:
// https://developer.mozilla.org/en-US/docs/Web/API/WorkerGlobalScope/importScripts
importScripts('path/to/appcache-behavior-import.js');
self.addEventListener('fetch', event => {
event.respondWith(goog.appCacheBehavior.fetch(event).catch(error => {
// Fallback behavior goes here, e.g. return fetch(event.request);
}));
});
goog.appCacheBehavior.fetch()
can be selectively applied to only a subset
of requests, to aid in the migration off of App Cache and onto a more
robust service worker implementation:
// Import the library into the service worker global scope:
// https://developer.mozilla.org/en-US/docs/Web/API/WorkerGlobalScope/importScripts
importScripts('path/to/appcache-behavior-import.js');
self.addEventListener('fetch', event => {
if (event.request.url.match(/legacyRegex/)) {
event.respondWith(goog.appCacheBehavior.fetch(event));
} else {
event.respondWith(goog.appCacheBehavior.fetch(event));
}
});
Parameters
event
FetchEventFAQs
A service worker implementation of the behavior defined in a page's App Cache manifest.
The npm package sw-appcache-behavior receives a total of 8 weekly downloads. As such, sw-appcache-behavior popularity was classified as not popular.
We found that sw-appcache-behavior demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.