From 64e6a32ce845aa1adf00f29be764c9e0678cca06 Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Sat, 9 Nov 2019 20:08:57 +0100 Subject: [PATCH] Display a message when a service worker updates --- gatsby-browser.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/gatsby-browser.js b/gatsby-browser.js index 80bfcec0..53866174 100644 --- a/gatsby-browser.js +++ b/gatsby-browser.js @@ -4,3 +4,15 @@ import './src/styles/global.scss' if (typeof window.IntersectionObserver === 'undefined') { import('intersection-observer') } + +// Display a message when a service worker updates +// https://www.gatsbyjs.org/docs/add-offline-support-with-a-service-worker/#displaying-a-message-when-a-service-worker-updates +export const onServiceWorkerUpdateReady = () => { + const answer = window.confirm( + `This application has been updated. ` + + `Reload to display the latest version?` + ) + if (answer === true) { + window.location.reload() + } +}