Created
October 7, 2013 23:50
-
-
Save clouddueling/6877043 to your computer and use it in GitHub Desktop.
Auto version js and css
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
<IfModule mod_rewrite.c> | |
RewriteRule ^(.*)\.[\d]{10}\.(css|js)$ $1.$2 [L] | |
</IfModule> |
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
/** | |
* Given a file, i.e. /css/base.css, replaces it with a string containing the | |
* file's mtime, i.e. /css/base.1221534296.css. | |
* | |
* @param $file The file to be loaded. Must be an absolute path (i.e. | |
* starting with slash). | |
*/ | |
public static function auto_version($file) | |
{ | |
$file = strpos($file, '/') === 0 ? $file : "/{$file}"; | |
if(!file_exists($_SERVER['DOCUMENT_ROOT'] . $file)) | |
return $file; | |
$mtime = filemtime($_SERVER['DOCUMENT_ROOT'] . $file); | |
return preg_replace('{\\.([^./]+)$}', ".$mtime.\$1", $file); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment