PaulTondeur / grunt-cache-busting

Cache busting files and updating references
8 stars 13 forks source link

Only 1st replacement done #10

Open vjirovsky opened 9 years ago

vjirovsky commented 9 years ago

Hello,

I use grunt-cache-busting tasks also for cache cleaning of sprite image (when I create new sprite by another task, the result is new Less file, but referencing to sprite image with no version), so I clean Less file by:

..
spritespngincss: {
                replace: ['www/css/sprites/partners.less'],
                replacement: 'partners.png',
                file: 'www/images/sprites/partners.png',
                get_param: true,
            }

_But cache-busting makes changes only for first apperance in file: _

/*partners.less*/
.partners-akc {
  display: block;
  background-image: url(../images/sprites/partners.png?v=dd7870f2a3d830f82b7bfbad54d34fcc);
  background-position: -300px -60px;
  width: 150px;
  height: 60px;
  box-sizing: border-box;
}
.partners-apek {
  display: block;
  background-image: url(../images/sprites/partners.png);
  background-position: -150px -285px;
  width: 150px;
  height: 60px;
  box-sizing: border-box;
}

Is there some parameter to force replace all apperance?

Thanks, Vaclav!

PaulTondeur commented 9 years ago

You are right, it seems like the replacement is just done once. Unfortunately I am not able to do fix, test and release this right now, but feel free to change the following lines https://github.com/PaulTondeur/grunt-cache-busting/blob/master/tasks/cache-busting.js#L23 https://github.com/PaulTondeur/grunt-cache-busting/blob/master/tasks/cache-busting.js#L41 and change the RegExes to global replacements instead and make a pull request for it.

Paul

tancnle commented 9 years ago

I am just pondering over the regex "((\-?)(.+)*)" on cache-busting.js#L41.

Considering this particular use case of <script type="text/javascript" src="js/main.js"></script><script>main.js</script> the new RegExp('main((-?)(.+)*).js', 'g') will clobber the second instance of main.js and produce undesirable behaviour.