reloadBrowser function

Future<void> reloadBrowser()

Reloads the page into the newest deployed version of the app.

A plain reload would come back to the same build. The service worker answers from the version it precached, and a newly deployed worker waits until no tab still runs the old one, which a reload does not change: the reloading tab is still one. So this first asks the browser for the newest worker, lets it finish precaching, has it take over, and only then reloads (decision 0014). Where there is no worker to update, or it will not cooperate in reasonable time, it reloads anyway.

Implementation

Future<void> reloadBrowser() async {
  try {
    await _activateNewestWorker().timeout(const Duration(seconds: 30));
  } on Object {
    // Nothing to activate, or the worker could not be reached: reload as is.
  }
  web.window.location.reload();
}