-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
amp-install-serviceworker: Trigger event when service worker has been update has been installed #18615
Comments
/cc @cramforce |
Added @ericlindley-g as he's been thinking about enhancements to |
I wonder if we should establish a standard mechanism to update from |
Agreed @cramforce. We should have the same standard, I'll write something up. |
❤️ I was wanting to write up something about this as well. In particular I had in mind: if a service worker is using a stale-while-revalidate strategy for caching navigation requests, as soon as revalidation results in there being an update to a cached response, the service worker needs to communicate a message to the client that there is an update to that URL and the user should be prompted to refresh. I'm sure you have something in mind already, but what comes to mind for me is a <amp-state id="stateFromServiceWorker">{}</amp-state>
<amp-install-serviceworker
on="message:AMP.setState({stateFromServiceWorker:event.data})"
src="https://www.example.com/serviceworker.js"
data-iframe-src="https://www.example.com/install-serviceworker.html"
layout="nodisplay"
></amp-install-serviceworker> Where messages could be sent from the service worker which could then populate the state via the event handler. |
I was thinking about something more imperative. And giving the SW itself access to the page's state. |
That's where I was headed as well. I'll put the document up tomorrow. |
@kristoferbaxter do we have any doc for this already? |
Any changes to amp-state without an explicit user gesture is forbidden from updating any UI. We might wanna re-visit that clause |
Assigning this to @choumx since we need the ability to pass messages between threads for amp-script too. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions. |
This is still desired. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions. |
At the moment there is no way to alert the user when an updated service worker has been installed. Often pages inform the user of this with a prompt such as:
I suggest that
amp-install-serviceworker
be extended to add support for anupdatefound
event which can be triggered on theamp-install-serviceworker
element.amphtml/extensions/amp-install-serviceworker/0.1/amp-install-serviceworker.js
Lines 293 to 303 in 9e9554c
Perhaps instead of
updatefound
it would be better to name itupdateinstalled
since as I understand we're primarily interested in when anupdatefound
event results in'installed' === registration.installing.state
being true. So perhaps something like so:With something like this in place, an author could then show a notice using
amp-bind
like so:(Maybe there should be an
AMP.reload()
action available as well.)Thoughts?
The text was updated successfully, but these errors were encountered: