Adding PWA Support to Composable Storefront
You can add Progressive Web Application (PWA) support to the composable storefront app. Composable storefront supports the latest major version of @angular/pwa.
Setting up PWA in Composable Storefront
Procedure
Limitations
-
The default ng server (webpack devserver
) does not provide support for service workers. You must use a separate HTTP server to support PWA. -
PWA is only supported in secure mode, so the HTTP server of your choice needs to serve composable storefront in secure (HTTPS) mode.
Hash Mismatch When Using Auto API Injection in SAP Commerce Cloud
If you are using the auto API injection mechanism in SAP Commerce Cloud, there is an index.html hash mismatch that can occur when hosting composable storefront as a PWA app in SAP Commerce Cloud.
When hosting composable storefront in SAP Commerce Cloud, the typical process is that the storefront application is built by generating all of the application files, the appropriate SHA1 hashes are put in the ngsw.json file, and when the application is run, all of the hashes match the files on the server.
However, if you are using SAP Commerce Cloud's auto API injection mechanism, there is a <meta name="occ-backend-base-url" content="OCC_BASE_URL_VALUE"> placeholder in the index.html file that is updated when a pod is started, but before the application itself starts. The OCC_BASE_URL_VALUE is replaced with the actual URL for the API endpoint in the environment where the application is currently deployed, which means the index.html file is changed when the placeholder is replaced. This results in a different hash for index.html, which in turn leads to a hash mismatch error in the service worker. As a result, the service worker (and by extension, PWA) does not work correctly anymore.
If the URL for the API endpoint is hardcoded in the index.html file, then no hash mismatch occurs, and hosting composable storefront as a PWA app in SAP Commerce Cloud works as expected.