protected function CssOptimizer::addDnsPrefetch in Advanced CSS/JS Aggregation 8.4
Same name and namespace in other branches
- 8.3 src/Asset/CssOptimizer.php \Drupal\advagg\Asset\CssOptimizer::addDnsPrefetch()
Extract any domains to prefetch DNS.
Parameters
array $asset: A core asset definition array.
Return value
array An array of domains to prefetch.
Overrides AssetOptimizer::addDnsPrefetch
File
- src/
Asset/ CssOptimizer.php, line 25
Class
- CssOptimizer
- The CSS Optimizer.
Namespace
Drupal\advagg\AssetCode
protected function addDnsPrefetch(array $asset) {
$prefetch = [];
if (!isset($asset['contents'])) {
return $prefetch;
}
$matches = [];
$pattern = '%url\\(\\s*+[\'"]?+(http:\\/\\/|https:\\/\\/|\\/\\/)([^\'"()\\s]++)[\'"]?+\\s*+\\)%i';
preg_match_all($pattern, $asset['contents'], $matches);
if (!empty($matches[1])) {
foreach ($matches[1] as $key => $match) {
$parse = @parse_url($match . $matches[2][$key]);
if (!empty($parse['host'])) {
$prefetch[] = $parse['host'];
}
}
}
return $prefetch;
}