Comments (5)
On each Page Refresh the Service Worker Script is polled for Updates.
127.0.0.1 - - [16/May/2021:23:15:23 +0100] "GET /service-worker HTTP/1.1" 200 - "-" "Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Firefox/78.0"
When the Browser finds that the script has changed it creates a new Instance of the Service Worker which is on hold for the Take Over.
When the Take Over is not executed the new Service Worker won't become active and the old version will continue to run forever.
from plack-pwa-web.
Introducing a ServiceWorker
Version and the Version Check with doCheckVersion()
it shows clearly that the Web Site is working with a different and outdated Version of the ServiceWorker
:
{"version":"0.0.1","cache":"dev-coffee-site-0.0.1","client_id":"189695f1-6bc2-421e-89db-b23222511b96"}
Version: '0.0.1'
While when downloading the ServiceWorker
Script it shows that the Version was already changed:
$ wget -S -O - http://localhost:3000/service-worker |grep -i sversion
--2021-05-23 13:12:24-- http://localhost:3000/service-worker
Resolviendo localhost (localhost)... ::1, 127.0.0.1
Conectando con localhost (localhost)[::1]:3000... falló: Conexión rehusada.
Conectando con localhost (localhost)[127.0.0.1]:3000... conectado.
Petición HTTP enviada, esperando respuesta...
HTTP/1.0 200 OK
Content-Type: text/javascript
Longitud: no especificado [text/javascript]
Grabando a: “STDOUT”
- [<=> ] 0 --.-KB/s var sversion = "0.0.2";
var staticDevCoffee = "dev-coffee-site-" + sversion;
version: sversion
- [ <=> ] 2,82K --.-KB/s en 0,008s
2021-05-23 13:12:24 (346 KB/s) - escritos a stdout [2890]
This becomes clear when looking on the ServiceWorkerRegistration
Object that holds 2 different Instances of the ServiceWorker
the old active ServiceWorker
and the new waiting ServiceWorker
Service worker registration succeeded:
ServiceWorkerRegistration { installing: null, waiting: ServiceWorker, active: ServiceWorker, scope: "http://localhost:3000/", updateViaCache: "imports", onupdatefound: null, pushManager: PushManager }
app.js:28:11
Service Worker installed 1:
ServiceWorkerRegistration { installing: null, waiting: ServiceWorker, active: ServiceWorker, scope: "http://localhost:3000/", updateViaCache: "imports", onupdatefound: null, pushManager: PushManager }
app.js:37:11
The current ServiceWorker
Version is polled from the active Instance:
doCheckVersion - go ... app.js:121:11
doCheckVersion - ServiceWorkerRegistration:
ServiceWorkerRegistration { installing: null, waiting: ServiceWorker, active: ServiceWorker, scope: "http://localhost:3000/", updateViaCache: "imports", onupdatefound: null, pushManager: PushManager }
app.js:122:11
Version - registration.active (object):
ServiceWorker { scriptURL: "http://localhost:3000/service-worker", state: "activated", onstatechange: null, onerror: null }
app.js:126:13
Version - registration.installing (object): null app.js:127:13
doCheckVersion - Request posting ... app.js:139:13
Got Message:
message { target: ServiceWorkerContainer, isTrusted: true, data: {…}, origin: "http://localhost:3000", lastEventId: "", source: ServiceWorker, ports: Restricted, srcElement: ServiceWorkerContainer, currentTarget: ServiceWorkerContainer, eventPhase: 2, … }
app.js:197:11
Message: Version Number '0.0.1' app.js:217:15
The OnUpdateFound
Event is not triggered because it happens when the new instance is created.
from plack-pwa-web.
The ServiceWorkerRegistration
state logged to the Browser Console shows that when there isn't a ServiceWorker
registered in the System yet the active
Property is still null
.
Service worker registration succeeded:
ServiceWorkerRegistration { installing: ServiceWorker, waiting: null, active: null, scope: "http://localhost:3000/", updateViaCache: "imports", onupdatefound: null, pushManager: PushManager }
app.js:28:11
Service Worker installed 1:
ServiceWorkerRegistration { installing: ServiceWorker, waiting: null, active: null, scope: "http://localhost:3000/", updateViaCache: "imports", onupdatefound: null, pushManager: PushManager }
app.js:40:11
So the ServiceWorker
in the installing
Property will become the active ServiceWorker
once the installation is completed.
It is also noticeable that the installing ServiceWorker
is still unresponsive to any Message Posts:
doCheckVersion - go ... app.js:81:11
doCheckVersion - ServiceWorkerRegistration:
ServiceWorkerRegistration { installing: ServiceWorker, waiting: null, active: null, scope: "http://localhost:3000/", updateViaCache: "imports", onupdatefound: null, pushManager: PushManager }
app.js:82:11
Version - registration.active (object): null app.js:86:13
Version - registration.installing (object):
ServiceWorker { scriptURL: "http://localhost:3000/service-worker", state: "installing", onstatechange: null, onerror: null }
app.js:87:13
doCheckVersion - Request posting ... app.js:99:13
So for the Update Detection a requirement must be that there is already an active ServiceWorker
instance:
doCheckUpdate - go ... app.js:129:11
doCheckUpdate - ServiceWorkerRegistration:
ServiceWorkerRegistration { installing: ServiceWorker, waiting: null, active: null, scope: "http://localhost:3000/", updateViaCache: "imports", onupdatefound: null, pushManager: PushManager }
app.js:130:11
Update - registration.installing (object):
ServiceWorker { scriptURL: "http://localhost:3000/service-worker", state: "installing", onstatechange: null, onerror: null }
app.js:134:13
Update - registration.waiting (object): null app.js:135:13
Service Worker Update detected! app.js:150:13
In the moment of installation the OnUpdateFound
Event is triggered, but on a newly registered ServiceWorker
the object was already moved ahead to the active
Property of the ServiceWorkerRegistration
Got Update:
updatefound { target: ServiceWorkerRegistration, isTrusted: true, srcElement: ServiceWorkerRegistration, currentTarget: ServiceWorkerRegistration, eventPhase: 2, bubbles: false, cancelable: false, returnValue: true, defaultPrevented: false, composed: false, … }
app.js:173:11
doCheckUpdate - go ... app.js:129:11
doCheckUpdate - ServiceWorkerRegistration:
ServiceWorkerRegistration { installing: null, waiting: null, active: ServiceWorker, scope: "http://localhost:3000/", updateViaCache: "imports", onupdatefound: null, pushManager: PushManager }
app.js:130:11
Update - registration.installing (object): null app.js:134:13
Update - registration.waiting (object): null app.js:135:13
Update: No Update waiting. app.js:144:15
from plack-pwa-web.
This development introduces a Version Poll Logic which polls the ServiceWorker
for it's Version and shows it on page.
In this Logic the Limitation was observed that when the ServiceWorker
is still installing it is unresponsive and does not process the submitted messages.
from plack-pwa-web.
About the static assets there was a Limitation observed that the Browser does not request the Server when it populates the ServiceWorker
Cache.
The Web Service Logs show that the assets were not requested from the Server only certain assets and the ServiceWoker
Script.
The Browser Network Insights document that those assets were populated in the Browser from the Disc Cache.
from plack-pwa-web.
Related Issues (5)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from plack-pwa-web.