Skip to content
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

PWA always loading in mobile offline mode. Only sometime it is working #332

Closed
Shailesh351 opened this issue Jun 29, 2020 · 5 comments · Fixed by #334
Closed

PWA always loading in mobile offline mode. Only sometime it is working #332

Shailesh351 opened this issue Jun 29, 2020 · 5 comments · Fixed by #334
Assignees

Comments

@Shailesh351
Copy link

No description provided.

@Shailesh351
Copy link
Author

@kb0304 @shubhsherl

The root cause of this issue is because of late registering of service worker. Many packages are fetched before service worker gets registered.
So when user first time loads the app and goes offline, app doesn't load because missing cached libraries.
But if user refreshing the app and then goes offline it works fine. Because all the libs are cached now on second refresh.

So we need to make sure service worker gets registered before fetching mail html page(with all the packages/libs)
Here's the open github issue for this issue in w3c/ServiceWorker repo w3c/ServiceWorker#1282

@shubhsherl
Copy link

@Shailesh351 The workaround mentioned in the issue above, solves the problem.

if (reg.installing) {
   const sw = reg.installing || reg.waiting;
   sw.onstatechange = function() {
      if (sw.state === 'installed') {
          // SW installed.  Reload for SW intercept serving SW-enabled page.
          window.location.reload();
      }
   };
}

@Shailesh351
Copy link
Author

Yes @shubhsherl I have tried that one. But it is not proper solution. In case of slow internet.

User waits for loading app -> then service worker gets registered -> Then again app reloads.

So we need to figure out other way around.

@shubhsherl
Copy link

@Shailesh351

User waits for loading app -> then service worker gets registered -> Then again app reloads.

But this will happen only on the first load of the app.

Another option is to add the minimum required requests in SW install listener, but this is not an efficient way, given there are many package requests.

@Shailesh351
Copy link
Author

Agree with you @shubhsherl. It will be for the first time loading only. I tried finding other ways but no luck. So we should go with this implementation. I am creating PR for the same

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants