1

Our site uses a great deal of static files in such way:

$cs = Yii::app()->clientScript;
$cs->registerCssFile(Yii::app()->staticServers[0]. 'static/css/site.css');
$cs->registerScriptFile(Yii::app()->staticServers[1]. 'static/js/site.js');

Where:

$staticServers = array('server1', 'server2',)

The question is: How to make user's browser cache to clear in this case after updating static files and downloading them.

Alex Ho
  • 299
  • 1
  • 2
  • 9

1 Answers1

1

Try just add nocache fix:

Yii::app()->clientScript->registerScriptFile(Yii::app()->staticServers[1]."static/js/site.js?nocache=".random(100, 999));

UPDATE try looking at this post

Community
  • 1
  • 1
Justinas
  • 41,402
  • 5
  • 66
  • 96
  • Sorry for misunderstanding. I stated the matter wrong. How to make user's browser cache to clear after updating static files? Your solution assumes permanent lack of caching. – Alex Ho Sep 02 '14 at 06:51
  • @user3929024 what you mean `clear cache after updating files`? You either ignore cache and take new file content or take file content from cache, i don't think that you can clear cache explicitly. – Justinas Sep 02 '14 at 06:57
  • I mean,that in Yii asset manager creates subfolders with specific na mes or change the names to prevent browers taking content from previously cached files due to new pathes. But it concerns files on the same machine. How about doing something similar with files on other servers? – Alex Ho Sep 02 '14 at 08:03