Home » , , » Prevent Your CSS and JavaScript Files From Being Cached

Prevent Your CSS and JavaScript Files From Being Cached

Written By Unknown on Kamis, 11 November 2010 | 21.25

Some websites use highly volatile, oft-changing CSS and JavaScript files. In the case of these files, it's important that the developer prevent browsers from caching them. How do we do that? By using a phantom querystring, of course. We'll use PHP to tack the current time onto the file reference.

The PHP


<link href="/stylesheet.css?<?php echo time(); ?>" rel="stylesheet" type="text/css" /&glt;

<-- RENDERS -->

<link href="/stylesheet.css?1234567890" rel="stylesheet" type="text/css" /&glt;


<script type="text/javascript" src="/site-script.js?<?php echo time(); ?>"></script> 

<-- RENDERS -->

<script type="text/javascript" src="/site-script.js?1234567890"></script>


It's a very simple technique and doesn't affect your CSS or JavaScript code in any way.
Share this article :

Posting Komentar

 
Support : Creating Website | Johny Template | Mas Template
Copyright © 2011. Kumpulan Kata Broadcast Blackberry - All Rights Reserved
Template Created by Creating Website Published by Mas Template
Proudly powered by Blogger