NekR / offline-plugin

Offline plugin (ServiceWorker, AppCache) for webpack (https://webpack.js.org/)
MIT License
4.52k stars 295 forks source link

In Angular 9, files inside directories are not being cached #482

Open navneet10sep opened 4 years ago

navneet10sep commented 4 years ago

After upgrading to Angular 9 and building the project, all the files inside the /dist folder at the root level are being cached but not the files that are in the subdirectory for example at location dist/asset/somefile.jpg

package.json

   "@angular/common": "^9.1.7",
    "@angular/compiler": "~9.1.4",
    "@angular/core": "~9.1.4",
    "@angular/platform-browser": "~9.1.4",
    "@angular/platform-browser-dynamic": "~9.1.4",
    "@angular/router": "~9.1.4",
 "@angular-builders/custom-webpack": "^8.2.0",
"@angular-devkit/build-angular": "~0.901.4",
"@angular/cli": "~9.1.4",
"@angular/compiler-cli": "~9.1.4",

"offline-plugin": "^5.0.7",

Sw.js

there is no path with /asset/* is added in the sw.js file.

var __wpo = {
    "assets": {
        "main": ["./0-es2015.65053c2240b70fdeb3f5.js", "./1-es2015.62ba28b3c9027abe300f.js", "./2-es2015.c5ac275d4e50c92569fd.js", "./runtime-es2015.03c7e090abe51828bcad.js", "./4-es2015.6c1eef279a1798644554.js", "./5-es2015.7aec8383ad4a076d198e.js", "./common-es2015.e3c42784e62096ade7f7.js", "./7-es2015.ff23c3f6c1f22ce1ad5c.js", "./main-es2015.9e9528dbc098f590a2f8.js", "./polyfills-es2015.12a1f690daaa82c12d9f.js", "./polyfills-es5.06ef848b06cdad2e2b0b.js", "./styles.2c01afa815e59ca5c393.css", "./12-es2015.07dc1b44739e96c7cc20.js", "./13-es2015.a2af176bde0c80ad0995.js", "./14-es2015.36af882e546b971e724b.js", "./15-es2015.bc33caeb15b951754238.js", "./16-es2015.df2c1246920b62e72421.js", "./17-es2015.fea7be462a4fea89c5eb.js", "./scripts.b9d7448dfdd3406f4c97.js"],
        "additional": [],
        "optional": []
    };

Loaded offline plugin using the following code


    new OfflinePlugin({
      publicPath: './',
      responseStrategy: 'cache-first',
      AppCache: false,
      caches: 'all',
      autoUpdate: true,
      version: '1.1',
      ServiceWorker: {
        events: true,
        ServiceWorker: {
          prefetchRequest: { credentials: 'same-origin' },
          minify: false
        },
      },
      cacheMaps: [
        {
          match:  (requestUrl) => {
            return new URL('/', location);
          },
          requestTypes: ['navigate']
        }
      ],
      excludes: ['**/*.config']

    })