Rahul Patil
Rahul Patil

Reputation: 25

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?

Upvotes: 2

Views: 447

Answers (1)

Robert Aparri
Robert Aparri

Reputation: 26

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']
            }]
        }
    }

Upvotes: 1

Related Questions