Add dns_prefetch for inline js domains.
Paramètres
array $js: JS array.
1 call to advagg_mod_find_inline_domains()
- advagg_mod_js_pre_alter dans advagg_mod/
advagg_mod.module - Alter the js array.
Fichier
-
advagg_mod/
advagg_mod.module, line 1883
Code
function advagg_mod_find_inline_domains(array &$js) {
$parsed = @parse_url($GLOBALS['base_root']);
$host = $parsed['host'];
foreach ($js as &$values) {
if ($values['type'] !== 'inline') {
continue;
}
// Find quoted strings in JS.
$matches = array();
$pattern = "/[\"'](.*?)[\"']/";
$matched = preg_match_all($pattern, $values['data'], $matches);
if (!$matched) {
continue;
}
// Find domains in the quoted strings and dns_prefetch it.
foreach ($matches[1] as $value) {
if (strpos($value, '//') !== FALSE) {
$parsed = @parse_url($value);
if (!empty($parsed['host']) && $host !== $parsed['host']) {
$values['dns_prefetch'][] = $value;
}
}
}
}
}