Forum Discussion

ChrisVocanic's avatar
ChrisVocanic
Contributor
13 years ago

Selecting correct external CSS between staging and production

Hi,

 

We have an implemnetation where we have a lot of CSS in an external file. (This allows us to make speedier updates). The external CSS is linked from the Community Style -> Custom Skin -> Wrapper -> Page Head Content box.

 

Is there a way that we can add a if or switch condition in the Page Head Content box to load a different CSS file depending on if we're accessing the staging environment or the production environment?

 

Thanks very much,

Chris

5 Replies

  • JasonL's avatar
    JasonL
    Lithium Alumni (Retired)
    13 years ago

    Hi Chris,

    its me :smileyhappy:

     

    Might be possible to use javascript document.url to switch css, however i seriously discourage this.

     

    Studio may be restrictive but it does serve very important role of version control. Every single change in CSS is tracked by version number with comments and we can roll-back to last working copy as needed.

     

    By referring to external CSS files, rolling back to specific version is no longer meaningful as there's other external CSS files that needs to be rolled back. This is in addition to the current issue you faced, both Staging/Production are pointing to the same set of external CSS files. Any changes will impact both Staging/Production.

     

    Best practice is to limit the number of external CSS file references.

  • cblown's avatar
    cblown
    Boss
    12 years ago

    I think you can put Freemarker into the head wrapper areas and use 

     

    ${http.request.url}

    to determine the requesting URL.

     

    Whether this is a good practice is debatable.

     

     

  • HaidongG's avatar
    HaidongG
    Lithium Alumni (Retired)
    12 years ago

    Hi Chris,

     

    try this config.getString, production returns "prod", stage server return "stage".

     

    <#function isStageServer>
        <#return (config.getString("phase", "stage") == "stage") />
    </#function>
    
    <#if isStageServer()>
    	//do something
    <#else>
    	//do something
    </#if>

     

    and as I know, Lithium hosts its html asserts automatically with CDN,so you don't need another party's CDN hosting.