[w3c/ServiceWorker] What is the correct way to notify the DOM thread about files that have been cached ? (#1260)

What is the correct way to notify the DOM thread about files that have been cached ? Ideally I display a progress bar, that reports the percentage (in KB or number of files) downloaded before the app is functional off-line.

I tried

```
const fillServiceWorkerCache2 = function () {
    /*It will not cache and also not reject for individual resources that failed to be added in the cache. unlike fillServiceWorkerCache which stops caching as soon as one problem occurs. see http://stackoverflow.com/questions/41388616/what-can-cause-a-promise-rejected-with-invalidstateerror-here*/
    return caches.open(CACHE_VERSION).then(function (cache) {
        return Promise.all(
            ressourcesToSaveInCache.map(function (url) {
                return cache.add(url).then(function(something) {
                    self.clients.matchAll().then(function(clientList) {
                        clientList.forEach(function(client) {
                            const message = {
                                intent: "update",
                                added: "url"
                            };
                            console.log(clientList, message);
                            client.postMessage(message);
                        });
                    });
                    return "success";
                }).catch(function (reason) {
                    self.clients.matchAll().then(function(clientList) {
                        clientList.forEach(function(client) {
                            const message = {
                                intent: "update",
                                failed: "url"
                            };
                            console.log(clientList, message);
                            client.postMessage(message);
                        });
                    });
                    return Promise.reject("error");
                });
            })
        );
    });
};
```

but it seems that postMessage does nothing

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/w3c/ServiceWorker/issues/1260

Received on Thursday, 18 January 2018 20:13:58 UTC