Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

why is the page taking an age to load? WordPress

  • SOLVED

I'm running a theme on www.techcityinsider.net and have just also (thanks to you guys) managed to get it working on a separate server here: http://92.243.24.134/ (debug info on)

the main index page and the page http://92.243.24.134/?page_id=258 are both taking an age to load, and for the life of me I can't figure out why.

I've tried running w3 total cache, sticking the theme files on a CDN, even put the dns through cloudflare, still no joy... it must be something to do with the theme... any ideas?

Also, here's a web page speed test i did on the www.techcityinsider.net website which shows where the delay is happening.. seemingly before most of the files are loading:

http://www.webpagetest.org/result/110914_AS_1KFN5/.

Answers (6)

2011-09-15

Jurre Hanema answers:

Please forget all the people who suggest that you optimize your JS etc. That is definitely not the problem here. The real problem is that <em>something</em> takes very long before the page even starts loading, so before the scripts and all that stuff even come into play.

What could this be? I don't know - it could be a poorly coded plugin, a poorly coded theme, or even a server issue. I have seen a problem very much like this in a case in which the programmer of the theme decided that it would be a good idea to perform some major database operations on every page load.

So, please start by de-activating all plugins. Is the page fast now? Then it is a problem with a plugin: try re-activating them one by one until you have found the one responsible for the slowness.

If it is not a problem with a plugin, switch back to the default theme. If the site is fast now it is probably a issue in your theme.

If the problem is not in a plugin or the theme, it may be a server issue or other problem. We can then try to look further, but I would definitely start by checking if the problem is in a plugin or the theme.

Also, some favicons you use on the side also load incredibly slow. I suggest you save them to your own server for faster load times.


Dave Smith comments:

thanks. I've now narrowed the issue down to the feed.php script by a process of elimination on the test site. See new much improved page load speed here: http://92.243.24.134/ now that the feed shortcode has been removed.

both the hp and the aggregator page use this feed.php file.

anyone got any ideas on what might be wrong with the code? On the homepage, it pulls in a combination of feed sources into one stream... on the TCi Aggregator page it pulls them into individual streams:

<?php function widget_sf_feed($args) {



ob_start();



if($args) extract($args); ?>



<?php if (!get_option(THEME_PREFIX . "rss_order")){



add_option(THEME_PREFIX . "rss_order", 2);



update_option(THEME_PREFIX . "rss_order", 2);



}







$more_url = get_option(THEME_PREFIX . "feed_site");



if( isset($args["more_url"]) && !empty($args["more_url"]) )



{



$more_url = $args["more_url"];



}



$args["description"] = '';



if( isset($args["description"]) && !empty($args["description"]) )



{



$description = $args["description"];



}







// Get RSS Feed(s)



include_once(ABSPATH . WPINC . '/feed.php');







// Get a SimplePie feed object from the specified feed source.



//$feed_url = get_option(THEME_PREFIX . "feed_url");



//$rss = fetch_feed('' . $feed_url . '');







$abbr_array = array();



if ($args["feeds"])



{



$abbr_array = explode("+",$args["feeds"]);



}







$show_excerpt = 1;



if (isset($args["excerpt"])){



$show_excerpt = intval($args["excerpt"]);



}







$feeds_arr = array();







$feeds_logo_arr = array();



$feeds_title_arr = array();



for($i=1;$i<get_option(THEME_PREFIX . "rss_order");$i++)



{



if (((sizeof($abbr_array)>0)&&in_array(get_option(THEME_PREFIX . "rss_abbr".$i),$abbr_array))||(!sizeof($abbr_array)))



{



array_push($feeds_arr, get_option(THEME_PREFIX . "rss_name".$i));



array_push($feeds_title_arr, get_option(THEME_PREFIX . "rss_title".$i));



array_push($feeds_logo_arr, get_option(THEME_PREFIX . "rss_logo".$i));



}



}







if( isset($args["columns"]) && ($args["columns"] >= 1) && (count($feeds_arr) > 0) )



{







$i = 0;



foreach($feeds_arr as $k=>$feed_url)



{



$rss = fetch_feed('' . $feed_url . '');



?>







<div id="rss-feed-columns" class="rss-feed-columns">



<div id="rss-feed-columns-header">



<h3><?=(empty($feeds_title_arr[$k])?'RSS':$feeds_title_arr[$k])?></h3>



<?



if (!empty($feeds_logo_arr[$k])) {



?>



<img src="<?php echo $feeds_logo_arr[$k] ?>" style="border:0; background:none; padding:0;" />



<?



} else {



?>



<img src="<?php bloginfo('template_url')?>/images/rss.png" style="border:0; padding:0;" />



<? }?>



</div>







<?php







// Figure out how many total items there are.



$rss_num = get_option(THEME_PREFIX . "rss_num");



if ($args["count"]) $rss_num = $args["count"];



if (!$rss->errors)



$maxitems = $rss->get_item_quantity($rss_num);







// Build an array of all the items, starting with element 0 (first element).



if (!$rss->errors)



$rss_items = $rss->get_items(0, $maxitems);



?>







<ul id="feed">



<?php if ($maxitems == 0) echo '<li>No items.</li>';



else



// Loop through each feed item and display each item as a hyperlink.



foreach ( $rss_items as $item ) : ?>



<li>



<h2<?=(!$show_excerpt ? ' class="excerpt"' : '')?>><a href="<?php echo $item->get_permalink(); ?>" title="<?=(!$show_excerpt ? strip_tags($item->get_description()) : 'Posted '.$item->get_date('j F Y | g:i a'))?>" target="_blank"><?php echo $item->get_title(); ?></a></h2>



<? if ($show_excerpt) {?>



<p><?php echo strip_tags($item->get_description()); ?></p>



<? }?>



</li>



<?php endforeach; ?>



</ul>



<div id="feed-last-item-columns"><!-- nothing to see here --></div>



<!--<a href="<?php echo $more_url?>" title="" target="_blank">View More</a>-->



</div> <!-- feed-feed -->







<?php



if( $i && ($i%3==2) ){



?>



<div style="clear:both; border-bottom:0px solid #CACACA;">&nbsp;</div>



<?php



}



$i++;



}







}



else



{



$rss = fetch_feed($feeds_arr);



?>







<div id="rss-feed" class="content-item">



<div class="content-dets">



<h3>Related on the web</h3>



<?



if (count($feeds_arr) == 1 && !empty($feeds_logo_arr[0])) {



?>



<img src="<?php echo $feeds_logo_arr[0] ?>" align="left" style="border:0; background:none; padding:0;" />



<?



} else {



?>



<? if (!empty($more_url)) {?>



<ul class="dets">



<li class="rss-link"><img src="<?php bloginfo('template_url')?>/images/rss.png" style="border:0; padding:0;" /> <a href="<?php echo $more_url?>" title="" class="rss-link" target="_blank">View More</a></li>



</ul>



<? } else {?>



<img src="<?php bloginfo('template_url')?>/images/rss.png" style="border:0; padding:0;" />



<? }?>



<? }?>











<? if (!empty($description)) {?>



<p><?=$description?></p>



<? }?>







<!--<ul class="dets">



<li class="rss-feed-link"><a href="<?php echo $more_url?>" title="<?php echo get_option(THEME_PREFIX . "feed_name"); ?>" target="_blank">View More</a></li>



</ul>-->



</div>







<div class="content-body feed-container">



<?php







// Figure out how many total items there are.



$rss_num = get_option(THEME_PREFIX . "rss_num");



if ($args["count"]) $rss_num = $args["count"];



if (!$rss->errors)



$maxitems = $rss->get_item_quantity($rss_num);







// Build an array of all the items, starting with element 0 (first element).



if (!$rss->errors)



$rss_items = $rss->get_items(0, $maxitems);



?>







<ul id="feed">



<?php if ($maxitems == 0) echo '<li>No items.</li>';



else



// Loop through each feed item and display each item as a hyperlink.



foreach ( $rss_items as $item ) : ?>



<li>



<h2<?=(!$show_excerpt ? ' class="excerpt"' : '')?>><a href="<?php echo $item->get_permalink(); ?>" title="<?=(!$show_excerpt ? strip_tags($item->get_description()) : 'Posted '.$item->get_date('j F Y | g:i a'))?>" target="_blank"><?php echo $item->get_title(); ?></a></h2>



<? if ($show_excerpt) {?>



<p><?php echo strip_tags($item->get_description()); ?></p>



<? }?>



</li>



<?php endforeach; ?>



</ul>







<div id="feed-last-item"><!-- nothing to see here --></div>



</div>



</div> <!-- feed-feed -->







<?php



}



?>







<?php if (!$args["widget_name"]){ ?>



<style>



#rss-feed {



padding-left: 0px;



width:660px !important;



border-bottom: none;



margin-top: 15px !important;



}



#rss-feed .content-dets h3 {



margin-top: 0px;



}



/*#rss-feed .content-body {



width:440px !important;



}*/



#rss-feed .content-dets {



width: 200px;



margin-left: 30px;



}







#rss-feed .content-body {



width:490px !important;



}







#rss-feed li {



width:490px !important;



}



</style>



<?php }?>







<?php



$result = ob_get_contents();



ob_end_clean();



return $result;



} register_sidebar_widget('Seven Five - Feed', 'widget_sf_feed');?>


Jurre Hanema comments:

With that code you are basically delaying the whole site until every single RSS feed has been loaded. As you have noticed, this can take a while.

There are better ways to load RSS feeds into your site, for example asynchronously via AJAX. It is also possible to check the feeds only at predetermined intervals (once per day for example) and cache the results.

There are probably a lot of plugins that can handle this for you.


Dave Smith comments:

can anyone point me in the direction of some code / plugins which will load them in a more friendly manner pls?

2011-09-14

Jens Filipsson answers:

Hey!
I can't even access the page, and that seems to be because of a plugin called cimy-user-extra-fields. Try to deactivate that plugin and see what happens!


Jens Filipsson comments:

Looking further at it, it looks like you´re low on memory. Maybe you should talk with your host about assigning more memory to your site?


Dave Smith comments:

both sites have memory limit set as follows:

php_value memory_limit 256M


Jens Filipsson comments:

Here's what you can try:

1. If you have access to your PHP.ini file, change the line in PHP.ini
If your line shows 32M try 64M:
memory_limit = 64M ; Maximum amount of memory a script may consume (64MB)

2. If you don't have access to PHP.ini try adding this to an .htaccess file:
php_value memory_limit 64M

3. Try adding this line to your wp-config.php file:
Increasing memory allocated to PHP
define('WP_MEMORY_LIMIT', '64M');

4. Talk to your host.


Jens Filipsson comments:

Oh sorry, I missed your reply there... You might wanna try step 3 in the guide I gave you, and see if that helps... Otherwise, I dont know.


Dave Smith comments:

pretty sure it's not to do with these errors, as i'm not getting them on the other site... take a look at that one, as i've just managed to completely break the other install!

2011-09-14

RNWest answers:

Also I see a error

register_sidebar_widget is <strong>deprecated</strong> since version 2.8! Use wp_register_sidebar_widget() instead.

FYI

2011-09-14

Fahad Murtaza answers:

Well its partly because of the error messages being loaded. You can disable wp-debug and all the plugins that you don't use in your theme. Start with that please and we can improve it further.


Dave Smith comments:

ok i've just managed to somehow completely break that demo install by trying to update the includes/functions.php file. lets work on the live install at www.techcityinsider.net

i've already added the new feed.php file with the fix, what next?

2011-09-14

Gabriel Reguly answers:

Hi Dave,

http://tools.pingdom.com/fpt/?url=undefined/&id=5697459

It tooks more than 7 seconds to just resolve your URL.

Are you running a multi-site install?

Also you could disable fancybox/cf7 for pages where it is not needed.

Regards,
Gabriel


Gabriel Reguly comments:

Hi Dave,

Surely you could start by solving the not found issues:

http://www.techcityinsider.net/wp-content/themes/seven-five/images/reply.jpg

Then load cf7 and fancybox only where they are needed.

This is for cf7, add it to your functions.php file:


// remove contact-form-7 overhead - cf7 is used only for page slug = contact
function my_dequeue_styles() {
if ( ! is_page( 'contact' ) ) {
wp_dequeue_style( 'contact-form-7' );
}
}
function my_dequeue_javascript() {
if ( ! is_page( 'contact' ) ){
wp_dequeue_script( 'contact-form-7' );
}
}
add_action( 'wp_print_styles', 'my_dequeue_styles', 100 );
add_action( 'wp_print_scripts', 'my_dequeue_javascript', 100 );


Regards,
Gabriel


Gabriel Reguly comments:

Hi Dave,

Seems to me it could be not WordPress, but a server related issue.

http://gtmetrix.com/reports/www.techcityinsider.net/n3Z01q3D

Check the timeline tab, that is more than 8 seconds waiting for the first content.

Maybe if you just put a static html page for testing this.

Regards,
Gabriel


Dave Smith comments:

Hey Gabriel, implemented the code in functions.php, no major change unfortunately. in terms of it being a server issue, that's what i also thought, which is why I set up the clone on a completely different server. This one is with Gandi: http://92.243.24.134/ and this one with Rackspace: http://techcityinsider.net/

in both instances, it's the HP and the TCi Aggregator pages which load slowly, which leads me to believe that it's not a server issue and must be theme related. All the other pages on the site load within a couple of seconds which is what i need for these two pages.


Dave Smith comments:

ps no, not running multi-site, and have fixed the reply.jpg issue, thanks for the heads up.


Gabriel Reguly comments:

Hi Dave,

Wow, homepage now is 7x faster. Jurre Hanema did provided you with the right directions.

Regarding images, what Jurre is saying is that you should have image files like http://www.leedsunited.pro/ldn/dollar.png
hosted at your server. (This one took 6 seconds to load)

For the AJAX RSS Reader, http://www.toptut.com/2010/04/26/how-to-display-rss-feeds-with-ajax-javascript/ seems a good solution.

If you ask another question about an AJAX RSS Reader, surely someone will suggest one that would be good for you.

Regards,
Gabriel

2011-09-14

Luis Abarca answers:

Turn off debugging and disable some plugins to let the theme run alone, so we can run a test with ySlow


Dave Smith comments:

I've turned off debugging, and as per Gabriel's post above have stopped cforms and fancybox loading on the hp (although I will eventually need fancybox back).


Luis Abarca comments:

You should change all the JS in the header to the footer.

Also change the conditional styles to this http://paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/


Luis Abarca comments:

You can change your theme to use http://html5boilerplate.com/, this site create a wordpress theme with HTML5 Boilerplate for you http://codekickoff.com/

Try to compress and minify your CSS and JS files too


Luis Abarca comments:

try to use a separate the html code in a template instead of using ob_start().

Using output control functions slow down a lot the display of the page, you can also flush the content early.

I notice that ou are still using the short tags, "<?" and "<?=", maybe theres nothing wrong with that, but its a lot better to use the standard tag "<?php"



function widget_sf_feed($args)

{

ob_start();



if ($args) extract($args);



if (!get_option(THEME_PREFIX . "rss_order")) {

add_option(THEME_PREFIX . "rss_order", 2);

update_option(THEME_PREFIX . "rss_order", 2);

}



$more_url = get_option(THEME_PREFIX . "feed_site");



if( isset($args["more_url"]) && !empty($args["more_url"]) ) {

$more_url = $args["more_url"];

}



$args["description"] = '';



if( isset($args["description"]) && !empty($args["description"]) ) {

$description = $args["description"];

}



// Get RSS Feed(s)

include_once(ABSPATH . WPINC . '/feed.php');



// Get a SimplePie feed object from the specified feed source.

//$feed_url = get_option(THEME_PREFIX . "feed_url");

//$rss = fetch_feed('' . $feed_url . '');



$abbr_array = array();



if ($args["feeds"]) {

$abbr_array = explode("+",$args["feeds"]);

}



$show_excerpt = 1;



if (isset($args["excerpt"])) {

$show_excerpt = intval($args["excerpt"]);

}



$feeds_arr = array();

$feeds_logo_arr = array();

$feeds_title_arr = array();



$feed_order = get_option(THEME_PREFIX . "rss_order");



for ($i = 1; $i < $feed_order; $i++) {

if (((sizeof($abbr_array) > 0) && in_array(get_option(THEME_PREFIX . "rss_abbr".$i), $abbr_array)) || (!sizeof($abbr_array))) {

array_push($feeds_arr, get_option(THEME_PREFIX . "rss_name".$i));

array_push($feeds_title_arr, get_option(THEME_PREFIX . "rss_title".$i));

array_push($feeds_logo_arr, get_option(THEME_PREFIX . "rss_logo".$i));

}

}



if (isset($args["columns"]) && ($args["columns"] >= 1) && (count($feeds_arr) > 0) ) {

$i = 0;



foreach($feeds_arr as $k=>$feed_url) {

$rss = fetch_feed('' . $feed_url . ''); ?>



<div id="rss-feed-columns" class="rss-feed-columns">

<div id="rss-feed-columns-header">

<h3><?php echo (empty($feeds_title_arr[$k])?'RSS':$feeds_title_arr[$k]) ?></h3>

<?php if (!empty($feeds_logo_arr[$k])) : ?>

<img src="<?php echo $feeds_logo_arr[$k] ?>" style="border:0; background:none; padding:0;" />

<?php else: ?>

<img src="<?php bloginfo('template_url') ?>/images/rss.png" style="border:0; padding:0;" />

<?php endif; ?>

</div>

<?php

// Figure out how many total items there are.

$rss_num = get_option(THEME_PREFIX . "rss_num");



if ($args["count"])

$rss_num = $args["count"];



if (!$rss -> errors)

$maxitems = $rss -> get_item_quantity($rss_num);



// Build an array of all the items, starting with element 0 (first element).



if (!$rss -> errors)

$rss_items = $rss -> get_items(0, $maxitems); ?>



<ul id="feed">

<?php if ($maxitems == 0): ?>

<li>No items.</li>

<?php else: ?>

<?php foreach ( $rss_items as $item ) : // Loop through each feed item and display each item as a hyperlink. ?>

<li>

<h2<?php echo (!$show_excerpt ? ' class="excerpt"' : '') ?>>

<a href="<?php echo $item -> get_permalink();?>" title="<?php echo (!$show_excerpt ? strip_tags($item->get_description()) : 'Posted '.$item->get_date('j F Y | g:i a'))?>" target="_blank"><?php echo $item -> get_title();?></a></h2>

<?php if ($show_excerpt) : ?>



<p>

<?php echo strip_tags($item -> get_description());?>

</p>

<?php endif ?>

</li>

<?php endforeach ?>

<?php endif ?>

<?php flush(); // show the content ?>

</ul>

<div id="feed-last-item-columns">

<!-- nothing to see here -->

</div>

<!--<a href="<?php echo $more_url?>" title="" target="_blank">View More</a>-->

</div>



<!-- feed-feed -->

<?php if( $i && ($i%3==2) ) : ?>

<div style="clear:both; border-bottom:0px solid #CACACA;">

&nbsp;

</div>

<?php endif ?>

<?php

$i++;

} // endforeach
<?php flush(); // show the content ?>

} else {

$rss = fetch_feed($feeds_arr); ?>

<div id="rss-feed" class="content-item">

<div class="content-dets">

<h3>Related on the web</h3>

<?php if (count($feeds_arr) == 1 && !empty($feeds_logo_arr[0])) : ?>

<img src="<?php echo $feeds_logo_arr[0] ?>" align="left" style="border:0; background:none; padding:0;" />

<?php else : ?>

<?php if (!empty($more_url)) : ?>

<ul class="dets">

<li class="rss-link"><img src="<?php bloginfo('template_url')?>/images/rss.png" style="border:0; padding:0;" /><a href="<?php echo $more_url?>" title="" class="rss-link" target="_blank">View More</a>

</li>

</ul>

<?php else: ?>

<img src="<?php bloginfo('template_url')?>/images/rss.png" style="border:0; padding:0;" />

<?php endif ?>

<?php endif ?>



<?php if (!empty($description)): ?>

<p><?php echo $description ?></p>

<?php endif ?>



<!--<ul class="dets">



<li class="rss-feed-link"><a href="<?php echo $more_url?>" title="<?php echo get_option(THEME_PREFIX . "feed_name"); ?>" target="_blank">View More</a></li>



</ul>-->

</div>

<div class="content-body feed-container">

<?php

// Figure out how many total items there are.

$rss_num = get_option(THEME_PREFIX . "rss_num");



if ($args["count"])

$rss_num = $args["count"];



if (!$rss -> errors)

$maxitems = $rss -> get_item_quantity($rss_num);



// Build an array of all the items, starting with element 0 (first element).

if (!$rss -> errors)

$rss_items = $rss -> get_items(0, $maxitems); ?>



<ul id="feed">

<?php if ($maxitems == 0): ?>

<li>No items.</li>

<?php else: ?>



<?php foreach ( $rss_items as $item ) : // Loop through each feed item and display each item as a hyperlink. ?>

<li>

<h2<?php echo (!$show_excerpt ? ' class="excerpt"' : '') ?>>

<a href="<?php echo $item->get_permalink() ?>" title="<?php echo (!$show_excerpt ? strip_tags($item->get_description()) : 'Posted '.$item->get_date('j F Y | g:i a'))?>" target="_blank"><?php echo $item -> get_title();?></a></h2>

<?php if ($show_excerpt): ?>

<p><?php echo strip_tags($item -> get_description());?></p>

<?php endif ?>

</li>

<?php endforeach ?>

<?php endif ?>

</ul>
<?php flush(); // show the content ?>


<div id="feed-last-item">

<!-- nothing to see here -->

</div>



</div>

</div>

<!-- feed-feed -->

<?php } ?>



<?php if (!$args["widget_name"]): ?>

<style>

#rss-feed {



padding-left: 0px;

width: 660px !important;

border-bottom: none;

margin-top: 15px !important;

}

#rss-feed .content-dets h3 {



margin-top: 0px;

}

/*#rss-feed .content-body {



width:440px !important;



}*/



#rss-feed .content-dets {



width: 200px;

margin-left: 30px;

}

#rss-feed .content-body {



width: 490px !important;

}

#rss-feed li {



width: 490px !important;

}

</style>

<?php endif ?>



<?php

$result = ob_get_contents();



ob_end_clean();



return $result;



} // end function



register_sidebar_widget('Seven Five - Feed', 'widget_sf_feed');


Dave Smith comments:

hey Luis, sorry my coding ain't good enough to be correcting this php myself... are you able to correct it and provide me with a revision to test please?


Luis Abarca comments:

Yes i can do it


Luis Abarca comments:

umm,m i install the theme and install the plugin, but it shows a lot of notices, because the theme use deprecated functions, i think that your best bet is install a plugin like this one http://wordpress.org/extend/plugins/better-rss-widget/

Rebuild your current Rss Widget gonna takes more time than expected.