Search code examples
csssasscompass-sass

Is there a way to prefix the url of an image referenced in .scss in case of CDN usage?


Currently in my .scss file I have

.grid_pic {
    width : $width-grid;
    background : transparent url('/img/exemple_bg.png') 0 0 repeat;
}

Is there a way of removing the /img/ and to define a variable, OR a configuration files that tells to prefix all the images with the value I want ?

So the day we decide to serve our images via CDN, we just have to change 1 config line from /img/ to http://cdn.example.com/ instead of changing all the Url of the images ?

How would you achieve that ? (a variable or is there already a config for that ?)

Thanks.


Solution

  • Try the interpolation syntax along with a variable:

    background: url(#{$path_variable_name}/site/background.jpg);