on( 'minify_js' ) && ( ! defined( 'DONOTMINIFYJS' ) || ! DONOTMINIFYJS ) && ! is_rocket_post_excluded_option( 'minify_js' ) ) { return $src; } return get_rocket_browser_cache_busting( $src, $current_filter ); } } if ( ! function_exists( 'get_rocket_browser_cache_busting' ) ) { /** * Create a cache busting file with the version in the filename * * @since 2.9 * @deprecated 3.1 * @author Remy Perona * * @param string $src CSS/JS file URL. * @param string $current_filter Current WordPress filter. * @return string updated CSS/JS file URL */ function get_rocket_browser_cache_busting( $src, $current_filter = '' ) { _deprecated_function( __FUNCTION__, '3.1' ); global $pagenow; if ( defined( 'DONOTROCKETOPTIMIZE' ) && DONOTROCKETOPTIMIZE ) { return $src; } if ( ! get_rocket_option( 'remove_query_strings' ) ) { return $src; } if ( is_user_logged_in() && ! get_rocket_option( 'cache_logged_user', 0 ) ) { return $src; } if ( 'wp-login.php' === $pagenow ) { return $src; } if ( false === strpos( $src, '.css' ) && false === strpos( $src, '.js' ) ) { return $src; } if ( false !== strpos( $src, 'ver=' . $GLOBALS['wp_version'] ) ) { $src = rtrim( str_replace( array( 'ver=' . $GLOBALS['wp_version'], '?&', '&&' ), array( '', '?', '&' ), $src ), '?&' ); } /** * Filters files to exclude from cache busting * * @since 2.9.3 * @author Remy Perona * * @param array $excluded_files An array of filepath to exclude. */ $excluded_files = apply_filters( 'rocket_exclude_cache_busting', array() ); $excluded_files = implode( '|', $excluded_files ); if ( preg_match( '#^(' . $excluded_files . ')$#', rocket_clean_exclude_file( $src ) ) ) { return $src; } if ( empty( $current_filter ) ) { $current_filter = current_filter(); } $full_src = ( substr( $src, 0, 2 ) === '//' ) ? rocket_add_url_protocol( $src ) : $src; switch ( $current_filter ) { case 'script_loader_src': $extension = 'js'; break; case 'style_loader_src': $extension = 'css'; break; } $hosts = get_rocket_cnames_host( array( 'all', 'css_and_js', $extension ) ); $hosts['home'] = rocket_extract_url_component( home_url(), PHP_URL_HOST ); $hosts_index = array_flip( $hosts ); $file = get_rocket_parse_url( $full_src ); if ( '' === $file['host'] ) { $full_src = home_url() . $src; } if ( false !== strpos( $full_src, '://' ) && ! isset( $hosts_index[ $file['host'] ] ) ) { return $src; } if ( empty( $file['query'] ) ) { return $src; } $relative_src = ltrim( $file['path'] . '?' . $file['query'], '/' ); $abspath_src = rocket_url_to_path( strtok( $full_src, '?' ), $hosts_index ); $cache_busting_filename = preg_replace( '/\.(js|css)\?(?:timestamp|ver)=([^&]+)(?:.*)/', '-$2.$1', $relative_src ); if ( $cache_busting_filename === $relative_src ) { return $src; } /* * Filters the cache busting filename * * @since 2.9 * @author Remy Perona * * @param string $filename filename for the cache busting file */ $cache_busting_filename = apply_filters( 'rocket_cache_busting_filename', $cache_busting_filename ); $cache_busting_paths = rocket_get_cache_busting_paths( $cache_busting_filename, $extension ); if ( file_exists( $cache_busting_paths['filepath'] ) && is_readable( $cache_busting_paths['filepath'] ) ) { return $cache_busting_paths['url']; } if ( rocket_fetch_and_cache_busting( $abspath_src, $cache_busting_paths, $abspath_src, $current_filter ) ) { return $cache_busting_paths['url']; } return $src; } } if ( ! function_exists( 'rocket_dns_prefetch_buffer' ) ) { /** * Inserts html code for domain names to DNS prefetch in the buffer before creating the cache file * * @since 2.0 * @deprecated 3.1 * @author Jonathan Buttigieg * * @param String $buffer HTML content. * @return String Updated buffer */ function rocket_dns_prefetch_buffer( $buffer ) { _deprecated_function( __FUNCTION__, '3.1' ); $dns_link_tags = ''; $domains = rocket_get_dns_prefetch_domains(); if ( (bool) $domains ) { foreach ( $domains as $domain ) { $dns_link_tags .= ''; } } $old_ie_conditional_tag = ''; /** * Allow to print an empty IE conditional tag to speed up old IE versions to load CSS & JS files * * @since 2.6.5 * * @param bool true will print the IE conditional tag */ if ( apply_filters( 'do_rocket_old_ie_prefetch_conditional_tag', true ) ) { $old_ie_conditional_tag = ''; } // Insert all DNS prefecth tags in head. $buffer = preg_replace( '//', '' . $old_ie_conditional_tag . $dns_link_tags, $buffer, 1 ); return $buffer; } }