How to parallelize downloads by hostname in WordPress?

I get this message "Parallel downloads by hostname" when checking my WordPress site on GTmetrix> https://gtmetrix.com

Here are the details> https://gtmetrix.com/parallelize-downloads-across-hostnames.html

How to fix it?

+4
source share
2 answers

More details

- , . , , , . , , , .

, . , 45 . , ( ), ( ), .


, WordPress.

/ /. :

  • example.com/wp-content/uploads/2015/11/myimage.jpg
  • media1.example.com/wp-content/uploads/2015/11/myimage.jpg
  • media2.example.com/wp-content/uploads/2015/11/myimage.jpg

functions.php

function parallelize_hostnames($url, $id) {
 $hostname = par_get_hostname($url);
 $url =  str_replace(parse_url(get_bloginfo('url'), PHP_URL_HOST), $hostname, $url);
 return $url;
}

function par_get_hostname($name) {
 //add your subdomains below, as many as you want.
 $subdomains = array('media1.mydomain.com','media2.mydomain.com');
 $host = abs(crc32(basename($name)) % count($subdomains));
 $hostname = $subdomains[$host];
 return $hostname;
}
add_filter('wp_get_attachment_url', 'parallelize_hostnames', 10, 2);
+9

HTTP/1.1, 6 .

HTTPS , HTTP/2, . HTTP/2 .

-

, , :

  • , : domain.com static1.domain.com static2.domain.com

  • functions.php WordPress. $subdomains .

/ /.

function parallelize_hostnames($url, $id) {
$hostname = par_get_hostname($url); //call supplemental function
$url = str_replace(parse_url(get_bloginfo('url'), PHP_URL_HOST), $hostname, $url);
return $url;
}

function par_get_hostname($name) {
$subdomains = array('static1.domain.com','static2.domain.com');
$host = abs(crc32(basename($name)) % count($subdomains));
$hostname = $subdomains[$host];
return $hostname;
}

add_filter('wp_get_attachment_url', 'parallelize_hostnames', 10, 2);

, , .

0

Source: https://habr.com/ru/post/1621165/


All Articles