Search code examples
google-chromeprogressive-web-appsworkbox

Why PWA App launched from "Add to Homescreen" can't load without Internet connection?


We have made our site (https://www.hijup.com) PWA ready with Add to HomeScreen capability. The app can be launched from the HomeScreen with Internet connection on. But when the connection is turned off, there is a dialog box as follow:

"To use [my_app_name] for the first time, please connect to the Internet"

Why does it still require Internet connection? All the JS & CSS are already precached (using workbox.precaching) and the start_url has been cached with networkFirst strategy. Moreover, it is not the first time I launched the app (as what the dialog message suggests).


Solution

  • This is resolved by fixing the route matcher:

    Previously it was:

     workbox.routing.registerRoute(new RegExp('www\\.hijup\\.com/id/$'), pagesHandler);
    

    The Regex doesn't match my start_url: "/en?utm_source=a2hs"

    The fix is to allow Regex to match suffix ?utm_source=a2hs

    workbox.routing.registerRoute(new RegExp('www\\.hijup\\.com/id/?(?:\\?.+)?$'), pagesHandler);