mischnic / parcel-plugin-sw-cache

📦👷 Parcel plugin for caching using a service worker
https://npm.im/parcel-plugin-sw-cache
MIT License
47 stars 6 forks source link

Thx. It worked for me: But just chrome, not fireFox, Don't know why #39

Open kaiwenxiao opened 2 years ago

kaiwenxiao commented 2 years ago

It worked for me:

config:

"cache": {
  "runtimeCaching": [
    {
      "urlPattern": "http://localhost:1234/cache.jpg",
      "handler": "staleWhileRevalidate",
      "options": {
        "broadcastUpdate": {
          "channelName": "api-updates"
        }
      }
    }
  ]
}

index.js

const updatesChannel = new BroadcastChannel('api-updates');
updatesChannel.addEventListener('message', event => {
        console.log(event);
});

index.html contained <img src="http://localhost:1234/cache.jpg">. Changing out cache.jpg fires the eventlistener.

Did you use staleWhileRevalidate?

Originally posted by @mischnic in https://github.com/mischnic/parcel-plugin-sw-cache/issues/4#issuecomment-371230274

kaiwenxiao commented 2 years ago

I give my API response updated, which will trigger this listener, and also skipWaiting() then refresh broswer