Dynamic URLs in CSS/JS

后端 未结 9 887
别跟我提以往
别跟我提以往 2021-02-05 16:14

I\'m splitting up one of my larger apps and introducing a \'cdn\' url to house common objects like CSS, javascript, and images to avoid duplication. What I need to do, though, i

9条回答
  •  有刺的猬
    2021-02-05 16:32

    Searching for an answer to this too, I saw a simple one: create your css file with duplicate classes, one for scenario 1 (images load from same domain) and another for scenario 2 (images load from CDN).

    e.g.

    .container {background-image:url(my/site/image.png;)}
    .container-CDN {background-image:url(http://my.site.cdn.com/image.png;)}
    

    Then on your index.php introduce PHP to call the correct class

    e.g.

    ">
    

提交回复
热议问题