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

Never hitting to the server #63

Closed
burakcan opened this issue Jun 5, 2016 · 16 comments
Closed

Never hitting to the server #63

burakcan opened this issue Jun 5, 2016 · 16 comments

Comments

@burakcan
Copy link

burakcan commented Jun 5, 2016

Hi, i'm trying to use this plugin but i couldn't get it working right.

Webpack version: 2.1.0-beta.8
Plugin version: 3.2.1
Configuration:

      updateStrategy: 'all',
      version: '[hash]',
      publicPath: '/',
      relativePaths: false,
      ServiceWorker: {
        output: 'offline/sw.js'
      },

On the first load, everything is ok and the app works offline on the next launch. But when i update something and build again, the cache/sw won't update. Also, there's no hits in the server logs. What i'm doing wrong? Should i put the runtime call in a non-cached chunk?

@NekR
Copy link
Owner

NekR commented Jun 5, 2016

Hi @burakcan.

First of all, in your case SW can control only /offline/* requests scope, so it's surprisingly that it works for you at all. Do you test on localhost/HTTPS site or on simple domain?

Second thing is that SW doesn't update on refresh. It updates actually, but new SW doesn't take control of webpages unless you force it to do so or close all active tabs.

Third thing might be that I never tried this plugonv with webpack2, so everything might be broken with it.

@burakcan
Copy link
Author

burakcan commented Jun 6, 2016

Hi @NekR , thank you for the response;

Im trying on both localhost:port and local.localdomain.com:port, it's working :)

Yes, i'm aware that the sw doesn't take control unless all tabs are closed. But doing that doesn't help too.

There's not too much change on the surface api of webpack in 2. But did try it with webpack 1.x it was the same.

I'll try with a flat file structure by removing the /offfline/ path.
Thank you.

@NekR
Copy link
Owner

NekR commented Jun 6, 2016

and local.localdomain.com:port,

Is it https? SW won't work there unless it's https. AppCache is on by default in offline-plugin, so that might be AppCache, if domain not https.

@burakcan
Copy link
Author

burakcan commented Jun 6, 2016

No the domain is not https, it's falling back to AppCache on that. But on localhost, service workers should work without ssl.

Edit: AppCache is not updating too.

@burakcan
Copy link
Author

burakcan commented Jun 6, 2016

I've just tried it with the default configuration new OfflinePlugin() it's still not working :(

@NekR
Copy link
Owner

NekR commented Jun 6, 2016

@burakcan hmm.. weird. Does version/hash change when you build new version?

@burakcan
Copy link
Author

burakcan commented Jun 6, 2016

I don't update the version(package.json) but the hash changes:
screen shot 2016-06-06 at 08 48 55
I'll try again with webpack 1 now

@NekR
Copy link
Owner

NekR commented Jun 6, 2016

@burakcan then it shouldn't work for everyone. Are you sure browser receives new SW version? e.g. it shouldn't be cached.

Also offline-plugin doesn't work with Hot Reload, just in case you are using it.

@burakcan
Copy link
Author

burakcan commented Jun 6, 2016

I'm doing hot loading only in development (webpack config is separate).
How do i know if browser receives the new SW version? I guess it doesn't because there is no request in the server logs at all.
With webpack 1, nothing changed.

@NekR
Copy link
Owner

NekR commented Jun 6, 2016

You may go to Network tab in devtools and inspect sw.js request and check if response is the new SW (with updated hash). Also in Chrome Canary there is Application tab which shows all SWs, pending, active, etc. So it might be helpful too.

But, if your server never receives request for sw.js, then if's not downloaded, obviously. Do you test in Firefox or Chrome? Does server send any Cache-Control or other http cache headers for sw.js?

@burakcan
Copy link
Author

burakcan commented Jun 6, 2016

Ah sorry :) it's the cache-control header. Setting it to zero fixed. Thank you @NekR

So the update scenario is like this right?:

  • first load (install)
  • new build
  • second load (updates the sw, but changes don't take effect)
  • close the tab, open again
  • see the new content

@burakcan burakcan closed this as completed Jun 6, 2016
@NekR
Copy link
Owner

NekR commented Jun 6, 2016

@burakcan right. In latest Chromes (e.g. Canary) you can set "Update SW on every navigation" option. Very useful for development. In this case SW is downloaded before pages loads, reinstalled and then page is downloaded.

Other way is apply update manually (this will work you users too):

// config

new OfflinePlugin({
  ServiceWorker: {
    events: true
  }
})
// the app

runtime.install({
  onUpdating: () => {
    console.log('SW Event:', 'onUpdating');
  },
  onUpdateReady: () => {
    console.log('SW Event:', 'onUpdateReady');
    // Apply update when available
    runtime.applyUpdate();
  },
  onUpdated: () => {
    console.log('SW Event:', 'onUpdated');
    // Reload immediately when updated
    window.location.reload();
  }
});

@burakcan
Copy link
Author

burakcan commented Jun 6, 2016

Thank you so much @NekR
events are just what i'm looking for 💯

@tleunen
Copy link

tleunen commented Feb 17, 2017

What was the final solution for this?
I'm kinda having the same issue.

Here's what I see for the sw:
screen shot 2017-02-17 at 3 45 32 pm
Looks like the new SW never gets activated, even after a refresh

@NekR
Copy link
Owner

NekR commented Feb 17, 2017

Please read here about SW update process and related stuff: https://github.com/NekR/offline-plugin/blob/master/docs/updates.md

@tleunen
Copy link

tleunen commented Feb 17, 2017

Thanks :)

New SW doesn't start controlling pages until all tabs of your website are closed

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

No branches or pull requests

3 participants