0

With grunt-sw-precache, I am trying to cache my application:

'develop': {
        // staticFileGlobs: [
        //   'app/styles/**/*.css',
        //   'font/**/*.{woff,ttf,svg,eot}',
        //   'app/images/**/*.{gif,png,jpg}',
        //   'app/scripts/**/*.js',
        // ],
        staticFileGlobs: ['index.html','/app/**/*.{js,html,css,png,jpg,gif}'],
        stripPrefix: 'app',
        baseDir:'./',
        runtimeCaching: [{
          handler: 'networkFirst'
        }]
      },
    },

I always get:

Total precache size is about 0 B for 0 resources.

My directory structure looks like this:

  projectRoot
      ______app
         __________images
         __________styles
         __________controllers
             __________jsFilesHere
             ___________app.js
             _____________config.js
             _____________index.html
             _____________sw.js

I need to cache all my files to enable the application to run offline as well. For that matter I need to cache my entire app folder

How do I change this

staticFileGlobs: ['index.html','/app/**/*.{js,html,css,png,jpg,gif}'],

to be able to get this working?

I tried replacing it with:

staticFileGlobs: ['.'] as well. but yet I get the same message.

As suggested, I am now storing sw.js in app folder only and have removed /

 'develop': {
        navigateFallback: '/index.html',   
        staticFileGlobs: ['scripts/**/*.js'],
        stripPrefix: 'app',
        baseDir:'./app',
        runtimeCaching: [{
          handler: 'networkFirst'
        }]
      },

But still nothing changed

systemdebt
  • 4,589
  • 10
  • 55
  • 116

1 Answers1

0

All glob patterns are interpreted with the current working directory as the base by default. The two patterns you're using are:

  • index.html, but there's no index.html in your current working directory as per the directory listing your shared.
  • /app/**/*.{js,html,css,png,jpg,gif}, which should not include the leading / character.

Try removing the leading / character from your wildcard glob pattern, and figure out why your index.html isn't showing up in your output directory, and that will hopefully resolve the issue for you.

(I'm not sure what baseDir: './' signifies, as that's not one of the supported options for sw-precache.)

Jeff Posnick
  • 53,580
  • 14
  • 141
  • 167