Same name in other branches
  1. 5.0.x src/Asset/CssOptimizer.php \Drupal\advagg\Asset\CssOptimizer::addDnsPrefetch()
  2. 6.0.x src/Asset/CssOptimizer.php \Drupal\advagg\Asset\CssOptimizer::addDnsPrefetch()
  3. 8.x-4.x src/Asset/CssOptimizer.php \Drupal\advagg\Asset\CssOptimizer::addDnsPrefetch()

Overrides AssetOptimizer::addDnsPrefetch

Fichier

src/Asset/CssOptimizer.php, line 25

Classe

CssOptimizer
The CSS Optimizer.

Namespace

Drupal\advagg\Asset

Code

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;
}