Skip to content

Instantly share code, notes, and snippets.

@brentjanderson
Created July 11, 2012 19:54
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brentjanderson/3092857 to your computer and use it in GitHub Desktop.
Save brentjanderson/3092857 to your computer and use it in GitHub Desktop.
Yii Framework cache busting with Git and some magic page post-processing.
public function processOutput($output) {
$output = parent::processOutput($output);
$output = str_replace('.css', '.css?' . Yii::app()->params['git-hash'], $output);
$output = str_replace('.js', '.js?' . Yii::app()->params['git-hash'], $output);
return $output;
}
$output = array();
$gitHash = exec('git rev-parse --verify HEAD 2> /dev/null', $output); // Thanks to AD7six (http://stackoverflow.com/a/9193040/704939)
$gitHash = $output[0];
return array(
/* All your configuration settings down to params */
'params' => array(
'git-hash' => $gitHash,
),
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment