Last active
December 24, 2015 23:09
-
-
Save clouddueling/6877913 to your computer and use it in GitHub Desktop.
force load js and css with auto versioning
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
| // Concept | |
| public static function auto_version($url) | |
| { | |
| $file = $_SERVER['DOCUMENT_ROOT'] . '/' . $url; | |
| if(! is_file($file)) | |
| return $url; | |
| $mtime = filemtime($file); | |
| return preg_replace('{\\.([^./]+)$}', ".$mtime.\$1", URL::to_asset($url)); | |
| } | |
| // from L3 /laravel/html.php | |
| public static function script($url, $attributes = array()) | |
| { | |
| $url = static::auto_version($url); | |
| return "<script src='{$url}' " . static::attributes($attributes) . "></script>" . PHP_EOL; | |
| } | |
| public static function style($url, $attributes = array()) | |
| { | |
| $defaults = array('media' => 'all', 'type' => 'text/css', 'rel' => 'stylesheet'); | |
| $attributes = $attributes + $defaults; | |
| $url = static::auto_version($url); | |
| return "<link href='{$url}' " . static::attributes($attributes) . ">" . PHP_EOL; | |
| } |
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
| {{ HTML::script("js/whatever.js") }} | |
| outputs: | |
| https://whatever.com/js/whatever.js |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment