5 * Advanced CSS/JS aggregation module.
7 * File used to store hook_advagg_* hooks.
11 * Implements hook_advagg_scan_file_alter().
13 * Used to make sure the add/modify the file meta data saved in the database.
15 function advagg_advagg_scan_file_alter($file, &$data) {
16 // Capture hosts for DNS prefetching.
17 // Skip if not a css file.
18 if (empty($data['fileext']) || $data['fileext'] !== 'css') {
22 // Get domain names in this css file.
24 $pattern = '%url\(\s*+[\'"]?+(http:\/\/|https:\/\/|\/\/)([^\'"()\s]++)[\'"]?+\s*+\)%i';
25 preg_match_all($pattern, $data['contents'], $matches);
27 if (!empty($matches[1])) {
28 foreach ($matches[1] as $key => $match) {
29 $parse = @parse_url($match . $matches[2][$key]);
30 if (!empty($parse['host']) && empty($urls[$parse['host']])) {
31 $urls[$parse['host']] = $parse['host'];
34 $urls = array_values($urls);
37 $data['dns_prefetch'] = $urls;