Exemplo n.º 1
0
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;
}
Exemplo n.º 2
0
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;
}
Exemplo n.º 3
0
function __rocket_deactivate_lazyload_on_specific_posts()
{
    if (is_rocket_post_excluded_option('lazyload')) {
        add_filter('do_rocket_lazyload', '__return_false');
    }
    if (is_rocket_post_excluded_option('lazyload_iframes')) {
        add_filter('do_rocket_lazyload_iframes', '__return_false');
    }
}
Exemplo n.º 4
0
function __rocket_extract_js_files_from_footer()
{
    global $rocket_enqueue_js_in_footer, $wp_scripts, $pagenow;
    /** This filter is documented in inc/front/process.php */
    $rocket_cache_search = apply_filters('rocket_cache_search', false);
    if (isset($wp_scripts->in_footer) && !is_array($wp_scripts->in_footer) || !get_rocket_option('minify_js', false) || in_array($pagenow, array('wp-login.php', 'wp-register.php')) || defined('DONOTMINIFYJS') && DONOTMINIFYJS || defined('DONOTCACHEPAGE') && DONOTCACHEPAGE || is_rocket_post_excluded_option('minify_js') || is_404() || is_search() && !$rocket_cache_search) {
        return;
    }
    // Digg Digg (https://wordpress.org/plugins/digg-digg/)
    if (defined('DD_PLUGIN_URL')) {
        $rocket_enqueue_js_in_footer[] = DD_PLUGIN_URL . '/js/diggdigg-floating-bar.js';
    }
    // nrelate Flyout (https://wordpress.org/plugins/nrelate-flyout/)
    if (defined('NRELATE_PLUGIN_VERSION')) {
        $rocket_enqueue_js_in_footer[] = NRELATE_JS_DEBUG ? 'http://staticrepo.nrelate.com/common_wp/' . NRELATE_PLUGIN_VERSION . '/nrelate_js.js' : NRELATE_ADMIN_URL . '/nrelate_js.min.js';
    }
    $home_host = parse_url(home_url(), PHP_URL_HOST);
    $deferred_js_files = get_rocket_deferred_js_files();
    $excluded_js = get_rocket_exclude_js();
    $excluded_external_js = get_rocket_minify_excluded_external_js();
    foreach ($wp_scripts->in_footer as $handle) {
        $script_src = $wp_scripts->registered[$handle]->src;
        $script_src = strstr($script_src, '/wp-includes/js/') ? $wp_scripts->base_url . $script_src : $script_src;
        $script_src_cleaned = str_replace(array('http:', 'https:', '//' . $home_host), '', $script_src);
        if (in_array($handle, $wp_scripts->queue) && !in_array(parse_url($script_src, PHP_URL_HOST), $excluded_external_js) && !in_array($script_src, $deferred_js_files) && !in_array(parse_url($script_src, PHP_URL_PATH), $excluded_js) && !in_array(parse_url($script_src_cleaned, PHP_URL_PATH), $excluded_js)) {
            // Dequeue JS files without extension
            if (pathinfo($script_src, PATHINFO_EXTENSION) == '') {
                wp_dequeue_script($handle);
            }
            // Add protocol on external JS to prevent conflict
            if ($home_host != parse_url($script_src, PHP_URL_HOST) && strpos($script_src, 'http://') === false && strpos($script_src, 'https://') === false) {
                $script_src = set_url_scheme($script_src);
            }
            // Add dependency enqueued in the footer
            foreach ($wp_scripts->registered[$handle]->deps as $handle_dep) {
                if (in_array($handle_dep, $wp_scripts->in_footer)) {
                    $src = $wp_scripts->registered[$handle_dep]->src;
                    $src = strstr($src, '/wp-includes/js/') ? $wp_scripts->base_url . $src : $src;
                    $rocket_enqueue_js_in_footer[$handle_dep] = rocket_set_internal_url_scheme($src);
                }
            }
            $rocket_enqueue_js_in_footer[$handle] = rocket_set_internal_url_scheme($script_src);
        }
    }
}