Skip to content

Instantly share code, notes, and snippets.

View brewster1134's full-sized avatar

Brewster brewster1134

View GitHub Profile
@brewster1134
brewster1134 / sprockets-urlrewriter gem.md
Last active October 4, 2015 22:07
sprockets-urlrewriter gem

After spending much time looking into the various solutions for serving vendored CSS containing relative urls (with much help from Bibliographic Wilderness, I decided on using the sprockets-urlrewriter preprocessor.

After some adjustments to the regex used to identify and rewrite the CSS urls, there was one other issue.

Although the sprockets-urlrewriter claims to rewrite relative urls to absolute ones, what it really does is rewrites urls relative to itself, to urls relative to the root asset directory.

This means that if the CSS all being compiled into application.css, everything works great. However if in development you are debugging your assets (a default in Rails), each CSS is linked individually. This means that the newly re-written urls are relative to application.css, but referenced in a different css file.

This is still ok if the location of the