Created
May 7, 2012 18:42
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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