Last Updated: February 25, 2016
·
923
· mikezarandona

Cache Buster for Technologically-Challenged Clients

I'm a front-end web developer, and every so often I come across a client who has more trouble than most with all things technology. After three or four of our weekly review calls were spent clearing their browser cache and downloading a better browser, I decided to employ this trick to ensure I wouldn't have to go through this pain again.

For non-techie clients, I make a small adjustment anywhere I pull in an external JS or CSS resource, like so:

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

<style type="text/javascript" href="path/to/javascript.js?r=<?php echo time(); ?>"></style>

<br />
The secret sauce is a bit of PHP which appends a UTC time stamp to the end of the URL. When implemented in this fashion, the browser reads the URL to the resource as unique on each load, which bypasses any cached versions - ensuring your user is seeing the latest and greatest.