Serving CSS from a static domain

I want to serve my css and images from a static cookieless domain. Now my problem is how to point to images from my css files.

I do not want to program my domain in a css file, for example:

http://static.com/image.png

I would rather have a variable pointing to the image, so it works for every static domain that I use.

What is the best way to achieve this. Should I run the entire css file via php and add a static domain before all png links. The disadvantage of this is that I have to put all the CSS in html.

Or there is another optimized way to do this.

+2
source share
2 answers

When you pull css from a static domain, relative URLs in CSS point to the same domain. Thus, you can simply use relative paths and serve both css and images from this domain.

+2
source

As long as the images come from the same server to the stylesheet, using relative URIs should be sufficient.

From CSS Specification :

To create modular style sheets that are independent of the absolute location of the resource, authors can use relative URIs. Relative URIs (as defined in [RFC3986]) are permitted for the full URI using the base URI. RFC 3986, section 5, defines the regulatory algorithm for this process. For CSS style sheets, the base URI is a sheet style style, not a document source.

There is an interesting essay by Bert Bos (one of the authors of the CSS specification) about variables in style sheets. You can read it here .

+6
source

Source: https://habr.com/ru/post/1309044/


All Articles