Jetpack::dns_prefetch PHP Method

dns_prefetch() public static method

Stores and prints out domains to prefetch for page speed optimization.
public static dns_prefetch ( mixed $new_urls = null )
$new_urls mixed
    public static function dns_prefetch($new_urls = null)
    {
        static $prefetch_urls = array();
        if (empty($new_urls) && !empty($prefetch_urls)) {
            echo "\r\n";
            foreach ($prefetch_urls as $this_prefetch_url) {
                printf("<link rel='dns-prefetch' href='%s'>\r\n", esc_attr($this_prefetch_url));
            }
        } elseif (!empty($new_urls)) {
            if (!has_action('wp_head', array(__CLASS__, __FUNCTION__))) {
                add_action('wp_head', array(__CLASS__, __FUNCTION__));
            }
            foreach ((array) $new_urls as $this_new_url) {
                $prefetch_urls[] = strtolower(untrailingslashit(preg_replace('#^https?://#i', '//', $this_new_url)));
            }
            $prefetch_urls = array_unique($prefetch_urls);
        }
    }

Usage Example

Example #1
0
<?php

/**
 * Module Name: VideoPress
 * Module Description: Powerful, simple video hosting for WordPress
 * First Introduced: 2.5
 * Free: false
 * Requires Connection: Yes
 * Sort Order: 27
 * Module Tags: Photos and Videos
 * Feature: Writing
 * Additional Search Queries: video, videos, videopress
 */
Jetpack::dns_prefetch(array('//v0.wordpress.com'));
/**
 * We won't have any videos less than sixty pixels wide. That would be silly.
 */
define('VIDEOPRESS_MIN_WIDTH', 60);
include_once dirname(__FILE__) . '/videopress/utility-functions.php';
include_once dirname(__FILE__) . '/videopress/shortcode.php';
include_once dirname(__FILE__) . '/videopress/videopress.php';
All Usage Examples Of Jetpack::dns_prefetch
Jetpack