rewrite URLs in CSS files

Posted by Don on Stack Overflow See other posts from Stack Overflow or by Don
Published on 2010-06-15T16:26:10Z Indexed on 2010/06/15 22:02 UTC
Read the original article Hit count: 306

Filed under:
|

Hi,

I'm writing a Maven plugin that merges CSS files together. So all the CSS files that match /foo/bar/*.css might get merged to /foo/merged.css.

A concern is that in a file such as /foo/bar/baz.css there might be a property such as:

background: url("images/pic.jpg")

So when the file is merged into /foo/merged.css this will need to be changed to

background: url("bar/images/pic.jpg")

The recalculated URL obviously depends on 3 factors:

  • original URL
  • original CSS file location
  • merged CSS file location

Assuming that the original and merged CSS files are both on the same filesystem, is there a general formula (or Java library) that can be used to calculate the new url given these 3 inputs?

Thanks, Don

© Stack Overflow or respective owner

Related posts about java

Related posts about css