CSS no cache

19.Jul.2010

In this snippet we shall see what is the way of using CSS file with no cache. In order to achieve this, we could include different CSS file every time. We won’t actually include different CSS file, but we shall send new param. This way, we will trick browser into thinking that there is a new CSS loaded. Use following snippet to make CSS no cache:

1
2
3
4
5
<!-- By sending parameter which is created based upon timestamp,
       user will almost certainly have new number generated each time
       the page is loaded. This way he will be able to trick web browser
       and use CSS no cache. -->
<link href='css-no-cache.css?ver=<?php echo uniqid(); ?>' type='text/css' rel='stylesheet' />