function rocket_dns_prefetch($buffer) { $dns_link_tags = ''; $cdn_cnames = get_rocket_cdn_cnames(array('all', 'images', 'css_and_js', 'css', 'js')); // Don't add CNAMES if CDN is disabled HTTPS pages or on specific posts if (!is_rocket_cdn_on_ssl() || is_rocket_post_excluded_option('cdn')) { $cdn_cnames = array(); } $domains = array_merge($cdn_cnames, (array) get_rocket_option('dns_prefetch')); /** * Filter list of domains to prefetch DNS * * @since 1.1.0 * * @param array $domains List of domains to prefetch DNS */ $domains = apply_filters('rocket_dns_prefetch', $domains); if (count($domains)) { foreach ($domains as $domain) { $dns_link_tags .= '<link rel="dns-prefetch" href="' . esc_url($domain) . '" />'; } } // Insert all DNS prefecth tags in head $buffer = preg_replace('/<head(.*)>/', '<head$1><!--[if IE]><![endif]-->' . $dns_link_tags, $buffer, 1); return $buffer; }
function get_rocket_cdn_url($url, $zone = array('all')) { $cnames = get_rocket_cdn_cnames($zone); $wp_content_dirname = ltrim(str_replace(home_url(), '', WP_CONTENT_URL), '/') . '/'; if (defined('DONOTCDN') && DONOTCDN || (int) get_rocket_option('cdn') == 0 || empty($cnames) || !is_rocket_cdn_on_ssl() || is_rocket_post_excluded_option('cdn')) { return $url; } list($host, $path, $scheme, $query) = get_rocket_parse_url($url); $query = !empty($query) ? '?' . $query : ''; // Exclude rejected & external files from CDN $rejected_files = get_rocket_cdn_reject_files(); if (!empty($rejected_files) && preg_match('#(' . $rejected_files . ')#', $path) || !empty($scheme) && $host != parse_url(home_url(), PHP_URL_HOST)) { return $url; } if (empty($scheme)) { // Check if the URL is external if (strpos($path, $home) === false && !preg_match('#(' . $wp_content_dirname . '|wp-includes)#', $path)) { return $url; } else { $path = str_replace($home, '', ltrim($path, '//')); } } $url = rtrim($cnames[abs(crc32($path)) % count($cnames)], '/') . '/' . ltrim($path, '/') . $query; $url = rocket_add_url_protocol($url); return $url; }