Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only 1st replacement done #10

Open
vjirovsky opened this issue Mar 19, 2015 · 2 comments
Open

Only 1st replacement done #10

vjirovsky opened this issue Mar 19, 2015 · 2 comments

Comments

@vjirovsky
Copy link

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
Copy link
Owner

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
Copy link

tancnle commented Apr 15, 2015

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.

dario-ramos added a commit to bitprim/grunt-cache-busting that referenced this issue Jun 19, 2018
dario-ramos added a commit to bitprim/grunt-cache-busting that referenced this issue Jun 19, 2018
dario-ramos added a commit to bitprim/grunt-cache-busting that referenced this issue Jun 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants