Same name in other branches
- 5.0.x src/Asset/CssOptimizer.php \Drupal\advagg\Asset\CssOptimizer::addDnsPrefetch()
- 6.0.x src/Asset/CssOptimizer.php \Drupal\advagg\Asset\CssOptimizer::addDnsPrefetch()
- 8.x-3.x src/Asset/CssOptimizer.php \Drupal\advagg\Asset\CssOptimizer::addDnsPrefetch()
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;
}