Same name in other branches
- 5.0.x advagg_mod/src/Asset/DeferCss.php \Drupal\advagg_mod\Asset\DeferCss::defer()
- 6.0.x advagg_mod/src/Asset/DeferCss.php \Drupal\advagg_mod\Asset\DeferCss::defer()
- 8.x-3.x advagg_mod/src/Asset/DeferCss.php \Drupal\advagg_mod\Asset\DeferCss::defer()
Replace stylesheet links with preload & noscript links.
Paramètres
string $content: The response content.
Return value
string Updated content.
Fichier
-
advagg_mod/
src/ Asset/ DeferCss.php, line 55
Classe
- DeferCss
- Modify stylesheet links to defer them. May lead to Flash of unstyled content.
Namespace
Drupal\advagg_mod\AssetCode
public function defer($content) {
if ($this->external) {
$pattern = '/<link rel=["\']stylesheet["\'](.*)(href="[a-zA-Z0-9\\/_\\.\\-\\?\\:]*")(.*)\\/\\>/';
}
else {
$pattern = '/<link rel=["\']stylesheet["\'](.*)(href="\\/[a-zA-Z0-9][a-zA-Z0-9\\/_\\.\\-\\?]*")(.*)\\/\\>/';
}
$content = preg_replace_callback($pattern, [
$this,
'callback',
], $content);
// Put JS inline if configured.
if ($this->deferMethod === 0) {
$path = drupal_get_path('module', 'advagg_mod') . '/js/loadCSS.js';
if (!strpos($content, $path)) {
$path = Crypt::hashBase64($path . $this->counter);
}
else {
$path = str_replace('/', '\\/', $path);
}
$path = preg_quote($path, '/');
$pattern = "/<script src=['\"]\\/(.*{$path}.*)\\?.*['\"]>/";
$content = preg_replace_callback($pattern, [
$this,
'inlineScript',
], $content);
}
return $content;
}