Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Lazerproof/3722f4ff44c6fe922ab4fe40be6e9f80 to your computer and use it in GitHub Desktop.
Save Lazerproof/3722f4ff44c6fe922ab4fe40be6e9f80 to your computer and use it in GitHub Desktop.
/**
* Adds file modified date as query string and returns URL to given asset.
*
*
* @param $relPath string File path relative to /site/templates/, such as "assets/css/style.css"
* @return string URL with cache busting query parameter
*/
function assetUrl($relPath)
{
$fullPath = wire()->config->paths->templates . $relPath;
$modified = filemtime($fullPath);
$url = wire()->config->urls->templates . $relPath . "?v=$modified";
return $url;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment