• Resolved martinhult

    (@martinhult)


    Hi, my WordPress site has been loading very slowly. It takes the browser 5-6 sec to connect to the site after which it loads very fast. I have no idea what to cause this and page analysis gives no clue what the issue might be.

    I have the following plugins installed:
    – Shutter Reloaded
    – W3 Total Cache
    – WordPress Gzip Compression

    I also have Facebook comments enabled as well as a custom made theme built from scratch.

    Is there anything I can do to improve my sites performance that will bring down the time it takes to connect to the site?

    My websites adress is: http://www.martinhult.com/

    I appreciate any help or insight you might be able to provide. Thanks!

Viewing 11 replies - 1 through 11 (of 11 total)
  • Phil

    (@owendevelopment)

    I think the video requests to youtube and vimeo are the longest loading items on the page 700+ms each (Only checked the homepage though)

    Thread Starter martinhult

    (@martinhult)

    I did a speedtest on two different homepages to give a bit of insight into what might cause the delay and neither Vimeo/Youtube seems to be the major culprits although I might be reading the data the wrong way:

    http://www.webpagetest.org/result/120501_S8_464HB/1/details/
    http://tools.pingdom.com/fpt/#!/lh2jFh4cn/http://www.martinhult.com/

    Thread Starter martinhult

    (@martinhult)

    It’s the initial connection slowdown that I want to reduce, the rest doesn’t really matter much for me.

    Phil

    (@owendevelopment)

    It’s bizarre. When I rerun the speed test, it seems the browser waits ~5 seconds to connect. Not the videos, not images, not javascript. Maybe the domain?

    If you use firefox, maybe download the YSlow plugin to analyse what is taking so long…

    Thread Starter martinhult

    (@martinhult)

    I found out why the page loads to slow. It’s because I’ve integrated Facebook comments into the feed. WordPress has to check all posts and their current comment count before the site loads.

    I have no idea how to fix it though as it isn’t a plugin per se but rather hardcoded into the homepage.

    Thread Starter martinhult

    (@martinhult)

    What I’d like to do is to make the comments load AFTER I’ve loaded the entire site but I dunno how to do that…

    Thread Starter martinhult

    (@martinhult)

    Anyone knows how I can cache the “fb_comment_count” function without using a plugin??

    This is my fb code:

    function fb_comment_count() {
    
        global $post;
        $url = get_permalink($post->ID);
    
        $filecontent = file_get_contents('https://graph.facebook.com/?ids=' . $url);
        $json = json_decode($filecontent);
        $count = $json->$url->comments;
        if ($count == 0 || !isset($count)) {
            $count = 0;
        }
        echo $count;
    }

    simple cache implementation

    function fb_comment_count() {
    
    $exptime = 900; // 1h = 3600s
    $file = 'fbcc_cache.txt'; //cache file
    
        global $post;
        $url = get_permalink($post->ID);
    
    if (!file_exists($file) || filesize($file)==0 || ((time()-filemtime($file)) > $exptime)) {
     $filecontent = file_get_contents('https://graph.facebook.com/?ids=' . $url);
     file_put_contents($file, $filecontent, LOCK_EX);
    }
    else $filecontent = file_get_contents($file);
    
        $json = json_decode($filecontent);
        $count = $json->$url->comments;
        if ($count == 0 || !isset($count)) {
            $count = 0;
        }
        echo $count;
    }

    Thread Starter martinhult

    (@martinhult)

    The code surely made the loading of the site a lot quicker but it seems to have broken the code somehow. Now it says that all posts has 0 comments…

    This is what the .txt file says:

    {"http:\/\/www.martinhult.com\/archives\/572":{"id":"http:\/\/www.martinhult.com\/archives\/572","shares":4}}

    ..ah, sorry. Single file, multiple pages :-p
    You must create cache folder and try something that:

    function fb_comment_count() {
        global $post;
        $url = get_permalink($post->ID);
    
    $exptime = 900; // 1h = 3600s
    $file = 'cache/fbcc_'.$post->ID.'.txt'; //cache file
    
    if (!file_exists($file) || filesize($file)==0 || ((time()-filemtime($file)) > $exptime)) {
     $filecontent = file_get_contents('https://graph.facebook.com/?ids=' . $url);
     file_put_contents($file, $filecontent, LOCK_EX);
    }
    else $filecontent = file_get_contents($file);
    
        $json = json_decode($filecontent);
        $count = $json->$url->comments;
        if ($count == 0 || !isset($count)) {
            $count = 0;
        }
        echo $count;
    }

    Thread Starter martinhult

    (@martinhult)

    Works like a charm! Thanks a lot! The initial load is slow, of course, but after that it loads really fast.

    Is there any other way to speed up the function call? ie. make it load after the rest of the page has loaded or something similar.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘My WordPress site loads really slow. Any ideas as to why?’ is closed to new replies.