Search code examples
angularcachingnpmgruntjsbrowser-cache

CacheBusting using grunt not updating references


I am using npm grunt-cache-bust for cache busting static files.

I have following folder structure

- app
    - scripts
         - app.js
         - app.config.js
         - controllers
             - controller1.js
             - controller12.js
    - index.html
- Gruntfile.js

In gruntfile.js i have added basic configuration

    cacheBust: {
      taskName: {
          options: {
              assets: ['dist/scripts/**'],
              jsonOutput: true,
              createCopies: true,
              deleteOriginals: false    
          },
          src: ['dist/index.html',]
      }
    }

It busts the file given in src but does not replace the reference in index.html

Is there something am I missing?


Solution

  • I ran into a similar issue and it was because the paths of my imports in my index.html did not have the form dist/scripts/**, but scripts/**. I solved it using specifying a baseDir for the file I want to be busted and cwd for the files which need their references updated:

        cacheBust: {
            taskName: {
                options:{
                    baseDir:'<%= somedir %>/',
                    assets:['**.js'],
                    deleteOriginals: true
                },
                files: [{
                    expand: true,
                    cwd: '<%= somedir %>/',
                    src: ['index.html']
                }]
            }
        }