Same name and namespace in other branches
  1. 5.0.x advagg_mod/src/Asset/DeferJs.php \Drupal\advagg_mod\Asset\DeferJs::defer() 1 commentaire
  2. 8.x-3.x advagg_mod/src/Asset/DeferJs.php \Drupal\advagg_mod\Asset\DeferJs::defer() 1 commentaire
  3. 8.x-4.x advagg_mod/src/Asset/DeferJs.php \Drupal\advagg_mod\Asset\DeferJs::defer() 1 commentaire

Add defer attribute to script tags.

Paramètres

string $content: The response content.

Return value

string Updated content.

Fichier

advagg_mod/src/Asset/DeferJs.php, line 82

Classe

DeferJs
Add defer tag to scripts.

Namespace

Drupal\advagg_mod\Asset

Code

public function defer($content) {
    // Admin Toolbar 8x fails when deferred.
    foreach ($this->skipList as $cid) {
        if (strstr($content, $cid)) {
            return $content;
        }
    }
    // Only defer local scripts.
    if ($this->deferType === 2) {
        $pattern = '/<script src="\\/[a-zA-Z0-0].*"/';
    }
    else {
        $pattern = '/<script src=".*"/';
    }
    return preg_replace_callback($pattern, [
        $this,
        'callback',
    ], $content);
}