Add preload link to the top of the html head.

Paramètres

string $url: Link to the url that will be preloaded.

string $media: Media types or media queries, allowing for responsive preloading.

string $as: What type of content is this; font, image, video, etc.

string $type: The mime type of the file.

string $crossorigin: Preload cross-origin resources; fonts always need to be CORS.

1 call to advagg_add_preload_link()
advagg_mod_page_alter dans advagg_mod/advagg_mod.module
Implements hook_page_alter().

Fichier

./advagg.module, line 6656

Code

function advagg_add_preload_link($url, $media = '', $as = '', $type = '', $crossorigin = NULL) {
    static $weight = -2000;
    $weight += 0.0001;
    $href = advagg_file_create_url($url);
    $key = "advagg_preload:{$href}";
    // Return here if url has already been added.
    $stored_head = drupal_static('drupal_add_html_head');
    if (isset($stored_head[$key])) {
        return TRUE;
    }
    // Add basic attributes.
    $attributes = array(
        'rel' => 'preload',
        'href' => $href,
    );
    // Fill in missing info.
    list($as, $type, $crossorigin) = advagg_get_preload_info_from_url($url, $as, $type, $crossorigin);
    // Exit if no as.
    if (empty($as)) {
        return FALSE;
    }
    // Build up attributes array.
    $attributes['as'] = $as;
    if (!empty($type)) {
        $attributes['type'] = $type;
    }
    if (!empty($crossorigin)) {
        $attributes['crossorigin'] = $crossorigin;
    }
    if (!empty($media)) {
        $attributes['media'] = $media;
    }
    // Call hook_advagg_preload_link_attributes_alter()
    drupal_alter('advagg_preload_link_attributes', $attributes);
    // Add to HTML head.
    $element = array(
        '#type' => 'html_tag',
        '#tag' => 'link',
        '#attributes' => $attributes,
        '#weight' => $weight,
    );
    drupal_add_html_head($element, $key);
    return TRUE;
}