PinoyTech.org

CodeIgniter, Kohana, Mootools, jQuery and CSS

How to Prevent CSS and Javascript Caching

Posted by teejay on March 19, 2009

As a developer or designer, it's not uncommon to bang our heads on the keyboard and say, “ Why isn't this working!!! @#$!!! ” and realized that the browser was just caching the file.

Javascript and CSS files tend to be cached by browsers and I have been recently using this technique to “ultimately” get rid of it.

For CSS

<link rel="stylesheet" href="http://pinoytech.org/css/styles.css<?php echo '?'.time();?>" media="screen,projection" type="text/css" />

For Javascript

<script href="http://pinoytech.org/script.js<?php echo '?'.time();?>"  type="text/javascript" ></script>

One quick solution when using Firefox when development is to press SHIFT+F5 and you flush the cache.

Categories: How To, Web Development

Tags: css, javascript

1 Comments

wayne

can you email me your javascript snippet to prevent caching,
the form just has: [remove][remove]

Thanks

August 6th 2009

Comments are not allowed