Forums

Peralelize image downloads across hostnames (3 posts)

  1. teknoledge
    Member
    Posted 2 years ago #

    Hi all,

    I have a simple function (in function.php) that replaces the image hostname to speedup page loading:

    function cdn_images() {
    	$content = ob_get_contents();
    	$pattern = '/src=[\\"\']?([^\\"\']?.*(png))[\\"\']?/i';
    	preg_match_all( $pattern, $content, $matches );
    	foreach($matches[1] as $val) {
    		$test = str_replace('www.domain.com', 'images.domain.com', $val);
    		echo $test.'<br />';
    	}
    }

    When placed on footer this obviously works well giving me new image paths. What I would like to do is to replace these images on the fly via WP hook.

    Anyone knows how to do this?

    Thanks!

  2. Jeremy Clark
    Moderator
    Posted 2 years ago #

    What I do is under the Misc. settings in the dashboard is an options for Full URL path to files, here you could just put http://images.domain.com keep in mind this would assume that you have images.domain.com and domain.com point to your wordpress installation. This will also only work for your media library not for images that are used in the theme.

  3. Frederick Townes
    Member
    Posted 2 years ago #

    W3 Total Cache (http://wordpress.org/extend/plugins/w3-total-cache/), will have exactly this type of functionality in it's upcoming release v0.9.

Topic Closed

This topic has been closed to new replies.

About this Topic