• This repository has been archived on 18/May/2021
  • Stars
    star
    163
  • Rank 231,141 (Top 5 %)
  • Language
    Objective-C
  • Created almost 10 years ago
  • Updated over 9 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Service Worker Plugin for iOS

This plugin adds Service Worker support to Cordova apps on iOS. To use it:

  1. Install this plugin.

  2. Create sw.js in your www/ directory.

  3. Add the following preference to your config.xml file:

    <preference name="ServiceWorker" value="sw.js" />
    

That's it! Your calls to the ServiceWorker API should now work.

Cordova Asset Cache

This plugin automatically creates a cache (called Cordova Assets) containing all of the assets in your app's www/ directory.

To prevent this automatic caching, add the following preference to your config.xml file:

<preference name="CacheCordovaAssets" value="false" />

Examples

One use case is to check your caches for any fetch request, only attempting to retrieve it from the network if it's not there.

self.addEventListener('fetch', function(event) {
    event.respondWith(
        // Check the caches.
        caches.match(event.request).then(function(response) {
            // If the response exists, return it; otherwise, fetch it from the network.
            return response || fetch(event.request);
        })
    );
});

Another option is to go to the network first, only checking the cache if that fails (e.g. if the device is offline).

self.addEventListener('fetch', function(event) {
    // If the caches provide a response, return it.  Otherwise, return the original network response.
    event.respondWith(
        // Fetch from the network.
        fetch(event.request).then(function(networkResponse) {
            // If the response exists and has a 200 status, return it.
            if (networkResponse && networkResponse.status === 200) {
                return networkResponse;
            }

            // The network didn't yield a useful response, so check the caches.
            return caches.match(event.request).then(function(cacheResponse) {
                // If the cache yielded a response, return it; otherwise, return the original network response.
                return cacheResponse || networkResponse;
            });
        })
    );
});

Caveats

  • Having multiple Service Workers in your app is unsupported.
  • Service Worker uninstallation is unsupported.
  • IndexedDB is unsupported.

Release Notes

1.0.1

  • Significantly enhanced version numbering.

1.0.0

  • Initial release.

More Repositories

1

mobile-chrome-apps

Chrome apps on Android and iOS
Python
2,501
star
2

chrome-cordova

Chrome APIs and integration layer for running Chrome Apps on mobile using Apache Cordova.
Objective-C
176
star
3

cordova-plugin-zip

Zip plugin for Cordova apps
C
168
star
4

cordova-plugin-background-app

Plugin to support background execution
Java
147
star
5

harness

Scripts for building the mobile Chrome Apps version of Apache's Cordova App Harness.
Java
104
star
6

mobile-chrome-app-samples

JavaScript
86
star
7

cordova-plugin-chrome-apps-sockets-udp

JavaScript
80
star
8

google-play-services

A Cordova plugin for Android that adds Google Play Services
Java
51
star
9

cordova-plugin-chrome-apps-sockets-tcp

JavaScript
44
star
10

cordova-plugin-service-worker-background-sync

Cordova Service Worker Background Sync Plugin
JavaScript
35
star
11

workshop-cca-eh

HTML
29
star
12

cordova-plugin-google-payments

Java
13
star
13

cordova-plugin-chrome-apps-usb

Java
13
star
14

cordova-plugin-chrome-apps-sockets-tcpServer

Java
12
star
15

cordova-plugin-chrome-apps-socket

JavaScript
12
star
16

cordova-plugin-chrome-apps-bootstrap

Plugin to run a Chrome app on top of Cordova
JavaScript
11
star
17

cordova-plugin-service-worker-geofencing

Cordova Geofencing Plugin
JavaScript
11
star
18

cordova-plugin-service-worker-notifications

Cordova Notification Plugin
JavaScript
11
star
19

cordova-plugin-service-worker-push

Push plugin for Cordova service worker
Objective-C
11
star
20

cordova-plugin-chrome-apps-alarms

JavaScript
10
star
21

cordova-plugin-chrome-apps-notifications

JavaScript
10
star
22

cordova-plugin-chrome-apps-bluetooth

Objective-C
10
star
23

cordova-plugin-chrome-apps-bluetoothLowEnergy

Java
9
star
24

cordova-plugin-chrome-apps-identity

JavaScript
9
star
25

cordova-plugin-android-support-v4

Adds the android-support-v4.jar to your project.
8
star
26

cordova-plugin-okhttp

Java
8
star
27

android-support

A Cordova plugin for Android that adds Android support libraries.
7
star
28

cordova-plugin-chrome-apps-gcm

JavaScript
5
star
29

syncNote

Demo app for chrome.syncFileSystem API
JavaScript
5
star
30

AndroidApkTemplate

JavaScript
5
star
31

cordova-plugin-chrome-apps-system-memory

Objective-C
5
star
32

cordova-plugin-chrome-apps-bluetoothSocket

Java
5
star
33

cordova-plugin-chrome-apps-system-cpu

Objective-C
5
star
34

cordova-plugin-chrome-apps-audioCapture

JavaScript
5
star
35

cca-push

Standalone Node tool to package and push Chrome apps to the Chrome ADT on mobile devices
JavaScript
4
star
36

cordova-plugin-chrome-apps-storage

JavaScript
4
star
37

cordova-plugin-chrome-apps-test-framework

Shared infrastructure for tests of Chrome Apps for Mobile plugins
JavaScript
3
star
38

cordova-plugin-chrome-apps-power

Java
3
star
39

cordova-plugin-chrome-apps-fileSystem

Objective-C
3
star
40

cordova-plugin-android-support-v7-appcompat

Adds the android-support-v7-appcompat.jar to your project.
3
star
41

cordova-plugin-chrome-apps-navigation

Objective-C
3
star
42

cordova-plugin-google-open-source-ios

Objective-C
3
star
43

experimental

For our early experiments
Objective-C
3
star
44

cordova-plugin-chrome-apps-videoCapture

JavaScript
2
star
45

cordova-plugin-chrome-apps-system-network

Objective-C
2
star
46

cordova-plugin-android-support-v7-mediarouter

Adds the android-support-v7-mediarouter.jar to your project.
2
star
47

cordova-plugin-chrome-apps-system-storage

Java
2
star
48

cordova-plugin-google-plus-ios

Cordova plugin for Google+ iOS SDK
Objective-C
2
star
49

cordova-plugin-blob-constructor-polyfill

JavaScript
2
star
50

sw2cdv

JavaScript
2
star
51

cordova-plugin-chrome-apps-i18n

JavaScript
2
star
52

cordova-plugin-customevent-polyfill

JavaScript
1
star
53

cordova-plugin-chrome-apps-common

JavaScript
1
star
54

cordova-plugin-xhr-blob-polyfill

JavaScript
1
star
55

cordova-plugin-chrome-apps-system-display

Java
1
star
56

cordova-plugin-chrome-apps-idle

JavaScript
1
star
57

cordova-plugin-chrome-apps-iosSocketsCommon

1
star
58

cordova-plugin-chrome-apps-runtime

JavaScript
1
star
59

cordova-plugin-chrome-apps-pushMessaging

Objective-C
1
star