Skip to content

Instantly share code, notes, and snippets.

@yoanmarchal
Forked from leowebguy/parallelize.php
Created March 29, 2016 08:46
Show Gist options
  • Save yoanmarchal/e766a79592bafa9506e4 to your computer and use it in GitHub Desktop.
Save yoanmarchal/e766a79592bafa9506e4 to your computer and use it in GitHub Desktop.

Revisions

  1. @leowebdev leowebdev revised this gist Nov 16, 2015. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions parallelize.php
    Original file line number Diff line number Diff line change
    @@ -1,3 +1,5 @@
    <?php

    /******
    Parallelize downloads across hostnames for WordPress.
    Useful to boost static resources load speed on websites.
  2. @leowebdev leowebdev revised this gist Nov 7, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion parallelize.php
    Original file line number Diff line number Diff line change
    @@ -19,7 +19,7 @@ function parallelize_hostnames($url, $id) {
    }

    function par_get_hostname($name) {
    $subdomains = array('media1.mydomain.com','media2.mydomain.com'); //add your subdomains here * as many as you want
    $subdomains = array('media1.mydomain.com','media2.mydomain.com'); //add your subdomains here, as many as you want.
    $host = abs(crc32(basename($name)) % count($subdomains));
    $hostname = $subdomains[$host];
    return $hostname;
  3. @leowebdev leowebdev revised this gist Nov 7, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion parallelize.php
    Original file line number Diff line number Diff line change
    @@ -19,7 +19,7 @@ function parallelize_hostnames($url, $id) {
    }

    function par_get_hostname($name) {
    $subdomains = array('media1.mydomain.com','media2.mydomain.com'); //add your subdomains here
    $subdomains = array('media1.mydomain.com','media2.mydomain.com'); //add your subdomains here * as many as you want
    $host = abs(crc32(basename($name)) % count($subdomains));
    $hostname = $subdomains[$host];
    return $hostname;
  4. @leowebdev leowebdev revised this gist Nov 7, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion parallelize.php
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    /******
    Parallelize downloads across hostnames for WordPress.
    Useful to boost page load for static resources.
    Useful to boost static resources load speed on websites.
    Recommended by GTmetrix, Pingdom, Google Speed Insights, and others.
    See full post > http://northeastcode.com/?p=2438
  5. @leowebdev leowebdev revised this gist Nov 7, 2015. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions parallelize.php
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,7 @@
    /******
    Parallelize downloads across hostnames for WordPress.
    Very useful to speed up page speed. Recommended by GTmetrix, Pingdom, Google Speed Insights, and others.
    Parallelize downloads across hostnames for WordPress.
    Useful to boost page load for static resources.
    Recommended by GTmetrix, Pingdom, Google Speed Insights, and others.
    See full post > http://northeastcode.com/?p=2438
    In order to work properly, all subdomains/hostnames MUST have the same structure/path. Ex:
  6. @leowebdev leowebdev revised this gist Nov 7, 2015. No changes.
  7. @leowebdev leowebdev renamed this gist Nov 7, 2015. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion functions.php → parallelize.php
    Original file line number Diff line number Diff line change
    @@ -1,12 +1,14 @@
    /******
    Parallelize downloads across hostnames for WordPress.
    Parallelize downloads across hostnames for WordPress.
    Very useful to speed up page speed. Recommended by GTmetrix, Pingdom, Google Speed Insights, and others.
    See full post > http://northeastcode.com/?p=2438
    In order to work properly, all subdomains/hostnames MUST have the same structure/path. Ex:
    http://mydomain.com/wp-content/uploads/2015/11/myimage.jpg
    http://media1.mydomain.com/wp-content/uploads/2015/11/myimage.jpg
    http://media2.mydomain.com/wp-content/uploads/2015/11/myimage.jpg
    Add to functions.php
    ******/

    function parallelize_hostnames($url, $id) {
  8. @leowebdev leowebdev revised this gist Nov 7, 2015. 1 changed file with 3 additions and 2 deletions.
    5 changes: 3 additions & 2 deletions functions.php
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,7 @@
    /******
    Parallelize downloads across hostnames for WordPress.
    Very usefull to speed up page speed. Recommended by GTmetrix, Pingdom, Google Speed Insights, and others.
    Parallelize downloads across hostnames for WordPress.
    Very useful to speed up page speed. Recommended by GTmetrix, Pingdom, Google Speed Insights, and others.
    See full post > http://northeastcode.com/?p=2438
    In order to work properly, all subdomains/hostnames MUST have the same structure/path. Ex:
    http://mydomain.com/wp-content/uploads/2015/11/myimage.jpg
  9. @leowebdev leowebdev created this gist Nov 7, 2015.
    23 changes: 23 additions & 0 deletions functions.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    /******
    Parallelize downloads across hostnames for WordPress.
    Very usefull to speed up page speed. Recommended by GTmetrix, Pingdom, Google Speed Insights, and others.
    In order to work properly, all subdomains/hostnames MUST have the same structure/path. Ex:
    http://mydomain.com/wp-content/uploads/2015/11/myimage.jpg
    http://media1.mydomain.com/wp-content/uploads/2015/11/myimage.jpg
    http://media2.mydomain.com/wp-content/uploads/2015/11/myimage.jpg
    ******/

    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('media1.mydomain.com','media2.mydomain.com'); //add your subdomains here
    $host = abs(crc32(basename($name)) % count($subdomains));
    $hostname = $subdomains[$host];
    return $hostname;
    }
    add_filter('wp_get_attachment_url', 'parallelize_hostnames', 10, 2);