Development tip: color coding UI by deployment platform

For anybody who’s working in web development, there often comes the situation where you have multiple deployments of an application. I my case the normal situation is to have a local working copy, a staging environment and a live environment.

I’m sure I’m not alone in having been in situations where I’ve made an update and then sat refreshing the browser scratching my head as to why the update isn’t showing, only to realise that I’ve been looking at the live version rather than the development version of the app or site.

To avoid this confusion and to avoid the need for checking the address bar when checking edits, I’ve been using different color schemes for each deployment platform. This gives an instant visual indication of which version is being viewed.

In the following example from Ackura PressRoom, I did a quick search and replace in the CSS files for the app to change the standard color code for headings and links. I also switched the logo to add an additional label and to match the color scheme.

PressRoom Local

Local development copy

PressRoom Staging

Staging environment

PressRoom Live

Live application

The downside of this is ensuring that the edited css files and images do not get copied when deploying updates. A solution to this would be to use override stylesheets that would be included dynamically acording to the host address for the page.

e.g.

mainstyle.css

h1,h2,a{
 color: #ff0000;
}

localcopy.css

h1,h2,a{
 color: #0000ff !important;
}

Then the header of the page could include something similar to this (pseudo code)

<link rel="stylesheet" href="mainstyle.css"/>
<?php if($hostname=='localhost'){ ?>
    <link rel="stylesheet" href="localcopy.css"/>
<?php } ?>

This technique would give the advantage of having the visual indicator of which environment was being viewed whilst allowing the code to be deployed in its entirety.

4 Responses

  1. Lee Kelleher says:

    Great idea, I should implement this on a few of the sites that I have developed.

    An alternative way to the CSS include could be to use the hostname in the class (or ID) of the body tag.

    e.g.
    <? if (hostname != ‘mainsite’) : ?>
    <body class=”<? echo hostname; ?>”>
    <? endif ?>

    Then you can use a single CSS file for the styles.

    i.e. body.localhost {background-color:red;}

  2. Dave says:

    nice idea Lee, yours is a simpler solution, however it does mean delivering redundant CSS to the client – not that it would be a big problem if the overrides were nice and compact.

  3. Lee Kelleher says:

    Yes, it seems to be a reoccurring theme for me lately… the balance between ease of development versus client performance. (i.e. Cutting the fat)

    I think anything under a couple of kilobytes would be acceptable… otherwise an external CSS is much better!

  4. Hello,
    Thanks for the great blog. I like your style of posting and useful information
    Which you always provide. Your post is really knowledgeable…

    Thanks Again…
    NET CREATIVE MIND TEAM
    http://www.netcreativemind.com

Leave a Reply