Getting over the Something’s wrong with the styles

  • 12 July

You can't even start to imagine how many times my office minions (co-workers) repeat that something I did doesn't work, just for them do discover that the version they see is the cached one.

Even when working on a online project it would be nice to have some sort of control over what the viewers see – preferably the newly changed version.

What I tend to use lately is generating a random marker in the URL while the project is still in development:

<link rel="stylesheet" type="text/css" href="/screen.css?<?= rand(0, 9999) ?>" />

Which constitutes in the file not being cached in general.

Now, that’s an acceptable solution before the project get deployed. After deployment it would be appropriate to generate a unique release of the template, in my case the catalogue structure would look like the below:

- templates
  - release_01_05_08
    - css
    - img
    - js
    - flash
    - misc
  - release_10_07_08
    - css
    - img
    - js
    - flash
    - misc

Of course the way you divide deployments in unique instances can use a simpler method – versioning for example:

<link rel="stylesheet" type="text/css" href="templates/v1/css/screen.css" />

That should solve common caching problems on all major browsers.

2 responses so far. Care to add one yourself?

  1. Tomasz Rondio July 14th, 2008 at 18:14

    • ctrl+f5 works great

  2. Oskar Krawczyk July 14th, 2008 at 20:58

    • Unfortunately your comment doesn’t even remotely touch the problem issued here. Command+R works fine for end-users, such as you or me, not for clients which mostly aren’t even aware of a button called F5. Also, the transition between style changes should be as seamless as it is possible.

Leave a Reply

Fill-in all the forms

Categories