SAP / spartacus

Spartacus is a lean, Angular-based JavaScript storefront for SAP Commerce Cloud that communicates exclusively through the Commerce REST API.
Apache License 2.0
744 stars 389 forks source link

Include ServiceWorker module in StorefrontModule #197

Closed marlass closed 5 years ago

marlass commented 6 years ago

It would be good if all PWA configuration will be placed inside StorefrontModule. Currently, we need to include ServiceWorkerModule beside StorefrontModule on app root. Look at PR #50 for more information.

Xymmer commented 6 years ago

Double-check with Tobias first

LTiger14 commented 6 years ago

We discussed this as part of the PWA PR. Filip and I thought it was a good idea. With @znikola and @dunqan we came up with a working solution for this.

znikola commented 6 years ago

PR #223

znikola commented 6 years ago

To test, first run the following: yarn build:core:lib, yarn build and yarn start:pwa. Open the devtools and verify that SW is running. You can also toggle offline mode and refresh - you should see part of the page that was cached and is served from the SW. After this, stop the app, and change the config in app.module.ts to:

...
      pwa: {
        enabled: false,
        ...
      }
...

Start the app again (yarn start:pwa), navigate to chrome's devtools application tab, clear everything, and refresh the page. Now, make sure that the SW is not running. Note: the SW will probably appear in the list, but it shouldn't be marked as running. If you toggle the offline switch again, and refresh, you should see the chrome's offline dinosaur.

znikola commented 6 years ago

Docs update proposal for: https://github.com/SAP/cloud-commerce-spartacus-storefront/pull/50#issuecomment-438271972

Set pwa.enabled and pwa.addToHomeScreen config to true in StorefrontModule configuration

StorefrontModule.withConfig({
      production: environment.production,
      server: {
        baseUrl: environment.occBaseUrl
      },
      pwa: {
        enabled: true,
        addToHomeScreen: true
      }
    })

Note that production flag in the StorefrontModule's config has to also be set to true.

gladius-mtl commented 6 years ago

Follow-up doc ticket GH-279 updated to include reference to doc input provided here. Thanks, @znikola ! 😄