1
0
mirror of https://github.com/restoreddev/phpapprentice.git synced 2025-08-12 09:44:27 +02:00

Added ability to version assets for browser cache busting

This commit is contained in:
Andrew Davis
2018-09-12 22:00:18 -05:00
parent 3f9679ff5b
commit c2bfe21c7a
5 changed files with 66 additions and 3 deletions

View File

@@ -147,3 +147,24 @@ function config(string $key) {
return $config[$key] ?? null;
}
/**
* Returns path to asset based on manifes.json file
*
* @param string $name
* @return string
*/
function asset(string $name): string {
$outputDir = config('output_dir');
if (file_exists($outputDir . '/manifest.json')) {
$text = file_get_contents($outputDir . '/manifest.json');
$paths = json_decode($text, true);
if (isset($paths[$name])) {
return $paths[$name];
}
}
return '/' . $name;
}