Skip to content

Instantly share code, notes, and snippets.

@axelf
Last active February 12, 2017 12:46
Show Gist options
  • Save axelf/9cde5972bc6c290a194ffe6b019ca3a9 to your computer and use it in GitHub Desktop.
Save axelf/9cde5972bc6c290a194ffe6b019ca3a9 to your computer and use it in GitHub Desktop.
Append a hash to the asset file for cache-busting
<?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