All Good Things Must Come To An End

As you all know, I have been doing WordPress plugins and supporting it for the past 6 years. These 6 years of my life, I have been through my polytechnic education, my national service as well as my university education.

I just graduated from university in December 2009 and have been looking for full-time jobs. I am offered a full-time job and will be starting work on 1st February 2010.

I regret to say that I am NOT ABLE to provide support for my plugins anymore due to my full-time job commitment. I will leave this forum open and let the community help one another.

However, I WILL still update my plugins whenever I can and you still can report bugs to me via email and I will try to fix it.

Author Topic: Improving load times of WP-Polls - Alfa  (Read 10511 times)

0 Members and 1 Guest are viewing this topic.

Offline Designer

  • Newbie
  • *
  • Posts: 2
    • View Profile
Improving load times of WP-Polls - Alfa
« on: 03 September 2008, 13:16 »
WordPress Version: 2.6
Theme: Customized theme
Blog URL: http://www.coolgrafimedia.com
Problem Plugin Name And Version: WP-Polls 2.31
PHP And MYSQL Version: PHP 5.2.5 MYSQL 4.1.20


Alfa: I am looking for testers and fellow programmers/ designers to help out with this.
** Do not use if you have no programming experience or on a production website. **



1. Combining the javascript in the polls into one external javascript file.

Combining all three javascripts into one file would reduce page-size and header requests
Whenever I try to pack, minify, or combine the javascript the poll's voting system stops working.  I haven't figured out what is causing this yet, or how to solve this.  Optimally I would like to load the javascript from one file. This would reduce the amount of header requests by one and reduce page-size. Note that polls-js-packed.js (Wp-Polls) is packed by default. This leaves tw-sack.js (Wordpress file) and the javascript included in the html. 

2.  Removed polls-css.css and incorporated styling css in theme css.

This reduced the header request by one. In order for the stylesheet to stop getting loaded in the page edited wp-polls.php  (see 1)


3. Moving the javascript from wp_head to wp_footer:

Yahoo Yslow recommends javascript being better of at the bottom of the page.  Note this cannot be done if the css is loaded in the wp_head in the standard wp-polls.php. You could possibly split up the echo statements in the wp-polls.php (I haven't tried this personally.) Changing wp_head in wp-polls.php to wp_footer loads the javascript in the footer while the polls remain working. (see 1)

4. Loading WP-Polls only on pages when there are polls. 

This could reduce load significantly on pages not using WP-Polls (or any other plugin). Something like this could be a solution:

Code: [Select]
<?php if ( in_category('number or name') ) { ?><?php wp_footer(); ?><?php } else { ?><?php ?>Note: Not sure if the last php statement is needed (in this case).

Testing shows using this it is possible to load the wp_footer  only when on the page with a poll. So far on my installation it only works for logged in users. When not logged in it ignores it and shows the polls javascript files on all pages. Haven't figured out why yet or what the cause is. Of course you could not have any other information in the wp_footer. So you would have to make this call before wp-footer. Using the footer.php for example enables you to only change the footer and not have to change any other theme files.

Using a config option in the backend to show in which post or category you would like to show the polls, would make it easier to use for daily users. This could be done with check boxes or list (or combination thereof) or something like the Widget Logic plugin.

1. wp-polls.php code |  line 184 - 203

Code: [Select]
### Function: Displays Polls Header
add_action('wp_footer', 'poll_header');
function poll_header() {
$poll_ajax_style = get_option('poll_ajax_style');
$pollbar = get_option('poll_bar');
wp_register_script('wp-polls', WP_PLUGIN_URL.'/wp-polls/polls-js-packed.js', false, '2.31');
echo "\n".'<!-- Start Of Script Generated By WP-Polls 2.31 -->'."\n";
echo '<script type="text/javascript">'."\n";
echo '/* <![CDATA[ */'."\n";
echo "\t".'var polls_ajax_url = \''.WP_PLUGIN_URL.'/wp-polls/wp-polls.php'."';\n";
echo "\t".'var polls_text_wait = \''.js_escape(__('Your last request is still being processed. Please wait a while ...', 'wp-polls')).'\';'."\n";
echo "\t".'var polls_text_valid = \''.js_escape(__('Please choose a valid poll answer.', 'wp-polls')).'\';'."\n";
echo "\t".'var polls_text_multiple = \''.js_escape(__('Maximum number of choices allowed:', 'wp-polls')).'\';'."\n";
echo "\t".'var poll_show_loading = '.intval($poll_ajax_style['loading']).';'."\n";
echo "\t".'var poll_show_fading = '.intval($poll_ajax_style['fading']).';'."\n";
echo '/* ]]> */'."\n";
echo '</script>'."\n";
wp_print_scripts(array('sack', 'wp-polls'));
echo '<!-- End Of Script Generated By WP-Polls 2.31 -->'."\n";
}

Hope it helps





« Last Edit: 03 September 2008, 15:22 by Designer »

Offline GaMerZ

  • lesterchan.net
  • Administrator
  • *****
  • Posts: 11,692
    • View Profile
  • WordPress Version: WordPress 3.0.x
  • Theme Name: lesterchan.net v3.4
Re: Improving load times of WP-Polls - Alfa
« Reply #1 on: 03 September 2008, 13:35 »
Wow nicely done, stickied.

++ lesterchan.net - Lester Chan's Website

I regret to say that I am not able to provide support for my plugins anymore due to my full-time job commitment. I will leave this forum open and let the community help one another.

Offline rickybuchanan

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Improving load times of WP-Polls - Alfa
« Reply #2 on: 13 November 2008, 12:23 »
Lester, are you planning to incorporate any speed-improving measures such as these into the plugin itself?

The external CSS stylesheet could easily be made optional with a tickybox on the admin page for those who were trying to speed things up.  I just realised that on some pages on my site SIX separate CSS files alone were being loaded for various plugins! I don't know much about the JavaScript side of things, but I'm trying to reduce the number of CSS files and I already have the relevant styling in my theme style sheet anyway. Please consider it a feature request :)

Thanks again,
r

Offline GaMerZ

  • lesterchan.net
  • Administrator
  • *****
  • Posts: 11,692
    • View Profile
  • WordPress Version: WordPress 3.0.x
  • Theme Name: lesterchan.net v3.4
Re: Improving load times of WP-Polls - Alfa
« Reply #3 on: 13 November 2008, 12:52 »
It is already done, the JS files are compressed and they are truly JS and not PHP files parse at JS. The CSS file that one can't be help, you can modify it to to suit your likings. By adding in just one more option just for that is not worth the load on the PHP/MYSQL side. You need to weigh a balance.

++ lesterchan.net - Lester Chan's Website

I regret to say that I am not able to provide support for my plugins anymore due to my full-time job commitment. I will leave this forum open and let the community help one another.

Offline rickybuchanan

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Improving load times of WP-Polls - Alfa
« Reply #4 on: 14 November 2008, 02:01 »
Cool! Thanks.

r