Given a link get the as, type, and crossorigin attributes.
Paramètres
string $url: Link to the url that will be preloaded.
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.
Return value
array An array containing
2 calls to advagg_get_preload_info_from_url()
- advagg_add_preload_header dans ./
advagg.module - Add in the preload header for CSS and JS external files.
- advagg_add_preload_link dans ./
advagg.module - Add preload link to the top of the html head.
Fichier
-
./
advagg.module, line 6592
Code
function advagg_get_preload_info_from_url($url, $as = '', $type = '', $crossorigin = NULL) {
// Get extension.
$parse = @parse_url($url);
if (empty($parse['path'])) {
return FALSE;
}
$file_ext = strtolower(pathinfo($parse['path'], PATHINFO_EXTENSION));
if (empty($file_ext)) {
$file_ext = basename($parse['path']);
}
// Detect missing parts.
$list = advagg_preload_list();
if (empty($as) && !empty($file_ext)) {
foreach ($list as $as_key => $list_type) {
$key = array_search($file_ext, $list_type);
if ($key !== FALSE) {
$as = $as_key;
// Type of font, ext is svg but file doesn't contain string font.
// This will be treated as an image.
if ($as === 'font' && $file_ext === 'svg' && stripos($url, 'font') === FALSE) {
$as = '';
}
}
if (!empty($as)) {
break;
}
}
}
if ($file_ext !== 'css' && empty($type) && !empty($as)) {
$type = "{$as}/{$file_ext}";
if ($file_ext === 'svg') {
$type .= '+xml';
}
if ($file_ext === 'js') {
$type = 'text/javascript';
}
if ($file_ext === 'css') {
$type = 'text/css';
}
}
if ($as === 'font' && is_null($crossorigin)) {
$crossorigin = 'anonymous';
}
return array(
$as,
$type,
$crossorigin,
$parse,
);
}