Angular PWA in IIS subfolder not work offline

前端 未结 3 778
灰色年华
灰色年华 2021-01-24 01:57

When I publish angular pwa application to subfolder in IIS, pwa application not work in offline.

ng build --prod --baseHref=/subfolder/ does not help.

I use htt

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-24 02:45

    The --baseHref=/mypath/ for building from Vinod led me the way, thanks!! Some more observations:

    • Angular's service-worker seems to be case sensitive on URLs: If in your ngsw.json you have /MyPath/index.html and someone runs the page typing mysite.com/mypath the service worker fails. Nasty! As per the spec the path of a URL is case-sensitive, but well...

    • If you use IIS: Just stopping a website will NOT simulate an offline situation for the Angular service-worker. You would have to stop the entire IIS.

    • From my observation the manifest does not matter for the service worker / offline functionality. You can comment it out in index.html. Required for install only. Vinod's values worked for that.

    Useful steps for newbies to follow what's going on:

    1. After a build check ngsw.json in dist. All files should be prefixed with /mypath/.

    2. After loading in Chrome check DevTools/Application/Cache storage. The entry "ngsw:/...:assets:app:cache" should contain the files from ngsw.json WITH /mypath/ prefix.

    3. Have DevTool/Network open when hitting F5 too see WHERE files come from. For files to work offline a refresh should show (ServiceWorker) in the size column.

    I found that putting baseHref in angular.json also works in this situation. Makes sense next to outputPath.

      "outputPath": "D:/somewhere/WwwRoot/full/public/path",
      "baseHref":"/full/public/path/",
    

提交回复
热议问题