Login  or  Register  / Search

Make CSS uncacheable

Sometimes it’s so tiring to purge cache for you able to use the latest css you have modified on your site if ever you are using a CDN such as CloudFlare, MaxCDN and etc. Now here’s the simple tips that will make CSS uncacheable.

Typical CSS Code :

<link rel="stylesheet" type="text/css" href="css/style.css">

Now to make it uncacheable using simple PHP date function

Uncacheable CSS Code :

<link rel="stylesheet" type="text/css" href="css/style.css?<?php echo date('h:i:s'); ?>">

Or another method we can use timestamp if you want to get rid of the colon

Uncacheable CSS Code using time() function :

<link rel="stylesheet" type="text/css" href="css/style.css?<?php echo date(); ?>">

The idea behind this technique is that the browser will will be tricked that it’s a new stylesheet which refresh every second.

So far it seems to work with us hopefully on yours too.