Alexandra Kovalenko
Alexandra Kovalenko

Reputation: 3

How to clean browser cache with the help of the code

I've made a lot of changes in the front end part of the project. But for applying them all users should clear the browser cache. Is there any way for cleaning users browsers cache from programming side?

Upvotes: 0

Views: 32

Answers (1)

mayersdesign
mayersdesign

Reputation: 5310

Yes, you need to version your static files. I use this trick:

<link href="/css/style.css?v=<?php echo filemtime($basepath."/css/style.css")?>" rel="stylesheet" type="text/css" />

Obviously that code will need adjustment, but you get the idea. It appends the file modification time as a version number on the file. So that every time it is changed (and only when it's changed) it completely busts the cache server and client side. Saves all those "I can't see any changes" calls from the clients! :)

Of course if you don't want to go the automatic route, you need only append the css (js etc) files with ?v=1.0 for example

Upvotes: 1

Related Questions