3

the url that is ignored by default in Create React App Service Worker is the following for firebase auth "__" urls, it is done like so:

navigateFallbackWhitelist: [/^(?!\/__).*/]

**using the same negative Regex method I tried adding to the array the following, "/dynamicHosting": **

Like so:

navigateFallbackWhitelist: [/^(?!\/__).*/, /^(?!\/dynamicHosting).*/]**

Problem is that Service Worker still keeps intercepting the path "/dynamicHosting"

Thus the 200.html my default navigateFallback file renders. instead of dynamic html file from my server.

Why is the ServiceWorker not ignoring the path "/dynamicHosting".

I am using SW-Precache CLI like so without ejecting from Create React App:

"build": "react-scripts build && sw-precache --config=sw-precache-config.js

Where the sw-precache-config.js looks like so:

module.exports = {
  staticFileGlobs: [
    './build/**/**.html',
    './build/images/**',
    './build/static/**',
    './build/manifest.json',
  ],
  dontCacheBustUrlsMatching: /\.\w{8}\./,
  swFilePath: './build/service-worker.js',
      // For unknown URLs, fallback to the index page
  navigateFallback: './200.html',
      // Ignores URLs starting from /__ (useful for Firebase):
  navigateFallbackWhitelist: [/^(?!\/__).*/, /^(?!\/dynamicHosting).*/],
  staticFileGlobsIgnorePatterns: [/\.map$/, /asset-manifest\.json$/, /404\.html$/],
  stripPrefix: './build'
}

UPDATE:

instead of a comma I had to write up the navigateFallbackWhitelist like so to combine the Regex:

after the following change it works:

navigateFallbackWhitelist: [/^(?!\/__).*/+ "|" +/^(?!\/dynamicHosting).*/],

jasan
  • 11,475
  • 22
  • 57
  • 97
  • See also https://stackoverflow.com/questions/49776235/how-do-i-exclude-urls-from-service-worker-scope-in-create-react-app-without-ha/63344095#63344095 – Wayne Bloss Aug 10 '20 at 16:24

0 Answers0