Skip to content

Instantly share code, notes, and snippets.

@mattbrundage
Created May 7, 2012 18:42
Show Gist options
  • Save mattbrundage/2629593 to your computer and use it in GitHub Desktop.
Save mattbrundage/2629593 to your computer and use it in GitHub Desktop.
Determines the file modification date and whether or not to append a query string to the file path
function assetQueryString ($filePath, $maxAge = 7) {
$today = intval(strtotime(date("Y-m-d")) / 86400);
$fileDate = intval(strtotime(date("Y-m-d", filemtime($_SERVER['DOCUMENT_ROOT'].$filePath))) / 86400);
$days = $today - $fileDate;
if ($days <= $maxAge) {
$filePath .= "?".$fileDate;
}
echo $filePath;
}
// more info: http://mattbrundage.com/2011/08/12/stale-cache-mitigation-with-query-string-automation/
//
// sample usage:
// <link rel="stylesheet" href="<?php assetQueryString("/templates/style/main.css"); ?>">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment