benhoIIand / grunt-cache-bust

Cache bust static assets using content hashing
MIT License
265 stars 103 forks source link

Relivative path problem + busted css lost #207

Open richardhinkamp opened 8 years ago

richardhinkamp commented 8 years ago

I'm trying to use this for a site and I'm running into 2 problems. See my test project: cache-buster.tar.gz Run run.sh to run grunt. This copies /src/ to /public/, this would be other grunt tasks for combining, preprocessing etc in a real project.

Problem 1: relative paths not correctly recognized

After running cache-bust, the CSS file is processed. background-image: url(../../assets/images/testbg.png); is changed to background-image: url(../../assets/images/testbg.1cad98e937926582.png); but background-image: url(../images/testbg.png); is left untouched. Shouldn't it figure out that this relative path does match 'assets/**' because public/assets/css/../images/ == public/assets/images/?

Problem 2: busted css is lost

After running, the file public/assets/css/application.css references the busted testbg.1cad98e937926582.png. But since this CSS file is referenced in index.html, is also gets a hashed copy public/assets/css/application.2464b055e944df27.css and this file references the normal testbg.png instead of the busted file. So this doesn't work together. Is this a bug, or should use some other kind of config to get this to work?

akoutmos commented 8 years ago

Running across this same issue. Particularly when paired with grunt-spritesmith. Worked around the relative path issue by using imgPath in spritesmith, but now the md5s are incorrect.

richardhinkamp commented 8 years ago

Problem 2 is because I provided a real filename instead of a wildcard as source. This file replaced with a hashed file so later the filename in de source config does not exist anymore and isn't processed. Will create new unit tests + fix in my pull request.

richardhinkamp commented 8 years ago

I added the unit test and fix yesterday btw.