Last active
February 12, 2017 12:46
-
-
Save axelf/9cde5972bc6c290a194ffe6b019ca3a9 to your computer and use it in GitHub Desktop.
Append a hash to the asset file for cache-busting
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 | |
/** | |
* Elixir asset helper | |
* | |
* @param string $file File name | |
* @return string | |
* | |
* @throws \InvalidArgumentException | |
*/ | |
function elixir($file) | |
{ | |
static $manifest = NULL; | |
if (is_null($manifest)) | |
{ | |
$manifest = json_decode(file_get_contents(FCPATH . '/build/rev-manifest.json'), TRUE); | |
} | |
if (isset($manifest[$file])) | |
{ | |
return '/build/' . $manifest[$file]; | |
} | |
throw new InvalidArgumentException("File {$file} not defined in asset manifest."); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment