Created
September 19, 2012 10:39
-
-
Save meglio/3748935 to your computer and use it in GitHub Desktop.
Generates file.ddd.js/css filenames based on their mtime
This file contains hidden or 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
<?php | |
namespace proj\utils; | |
class TimebasedUrl | |
{ | |
static function js($path) | |
{ | |
return '<script type="text/javascript" src="'.self::url($path).'"></script>'; | |
} | |
static function css($path) | |
{ | |
return '<link rel="stylesheet" href="'.self::url($path).'">'; | |
} | |
static function url($relPath) | |
{ | |
$domain = Web::protocolAgnostic(COOKIE_FREE_URL); | |
$file = ROOT.$relPath; | |
if (!file_exists($file) || !is_readable($file) | |
|| !($ext = pathinfo($relPath, PATHINFO_EXTENSION)) | |
|| false === ($time = filemtime($file))) | |
return $domain.$relPath; | |
return $domain.preg_replace('|\.'.$ext.'$|is', '.'.$time.'.'.$ext, $relPath); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Web::protocolAgnostic ?