From 982b22a676c258d641ee2c577ab514e5edb9d84a Mon Sep 17 00:00:00 2001 From: Sam Georges Date: Sat, 16 Aug 2014 09:17:09 +1000 Subject: [PATCH] Fixes #547 - Duplicate assets are pointless --- modules/system/traits/AssetMaker.php | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/modules/system/traits/AssetMaker.php b/modules/system/traits/AssetMaker.php index 6e5be3450..bd5c95c30 100644 --- a/modules/system/traits/AssetMaker.php +++ b/modules/system/traits/AssetMaker.php @@ -38,13 +38,21 @@ trait AssetMaker if ($type != null) $type = strtolower($type); $result = null; $reserved = ['build']; + $pathCache = []; if ($type == null || $type == 'css'){ foreach ($this->assets['css'] as $asset) { + /* + * Prevent duplicates + */ + $path = $this->getAssetEntryBuildPath($asset); + if (isset($pathCache[$path])) continue; + $pathCache[$path] = true; + $attributes = HTML::attributes(array_merge([ 'rel' => 'stylesheet', - 'href' => $this->getAssetEntryBuildPath($asset) + 'href' => $path ], array_except($asset['attributes'], $reserved) )); @@ -56,9 +64,16 @@ trait AssetMaker if ($type == null || $type == 'rss'){ foreach ($this->assets['rss'] as $asset) { + /* + * Prevent duplicates + */ + $path = $this->getAssetEntryBuildPath($asset); + if (isset($pathCache[$path])) continue; + $pathCache[$path] = true; + $attributes = HTML::attributes(array_merge([ 'rel' => 'alternate', - 'href' => $this->getAssetEntryBuildPath($asset), + 'href' => $path, 'title' => 'RSS', 'type' => 'application/rss+xml' ], @@ -72,8 +87,15 @@ trait AssetMaker if ($type == null || $type == 'js') { foreach ($this->assets['js'] as $asset) { + /* + * Prevent duplicates + */ + $path = $this->getAssetEntryBuildPath($asset); + if (isset($pathCache[$path])) continue; + $pathCache[$path] = true; + $attributes = HTML::attributes(array_merge([ - 'src' => $this->getAssetEntryBuildPath($asset) + 'src' => $path ], array_except($asset['attributes'], $reserved) ));