Javascript – How to specify base url for CSS and javascript

cssjavascript

Let's say I have style.css:

#some_element{
   background-image: url('img/picture.gif');
}

The css and picture.gif are located in such a structure:

style.css 
other_style.css
more_style.css
img
   picture.gif

Using php, I combine style.css,other_style.css and more_style.css into cache_style.css which is located far far away from the original location.

In this case, the link will be broken.

In html, we have tag to define (as it name) base url of current document. So that every link and every image can take things base on that base url.

Is there any alternative for css & javascript to do this?

EDIT: some of the css/javascript are minified third party, which is nearly impossible to change "img/picture.gif" into "/something/img/picture.gif"

Best Answer

Use an absolute path from the root directory that you're serving:

background-image: url('/img/picture.gif');