X

Changing the plugin file to utilize wordpress 2.8 optimization

WordPress 2.8 has been released few days ago.
It come with some sort of optimization.. as many had complaint regarding the placing of
JavaScript at the bottom of the page instead of at the beginning of the page.

As per Yahoo! why slow performance advice has stated that..
JavaScript pulling at the beginning of the page will slow the down the page loading, because it wait the javascript fully
loaded before start pulling the next item of the page.

Unlike the CSS, it tend to block async process before the JavaScript completed..

so , seem like the wordpress developer have heard the complaint..
The have add another argument to the existing ..

Oh.. you might have lost..

in a theme file..

there are normally had


and


and for plugin to ‘hook’ onto that part of the page to do something they had to have something like this in the plugin file.


the difference between 2.8 and any of previous version is :

       // for previous  than 2.8 version (2.7 ,2.3 )
 wp_enqueue_script('wp-name-of-the-plugin', plugins_url('wp-name-of-the-plugin/plugin-js-file.js'), array('jquery'), '2.50');
       // for  2.8 version 
 wp_enqueue_script('wp-name-of-the-plugin', plugins_url('wp-name-of-the-plugin/plugin-js-file.js'), array('jquery'), '2.50', true);

Mind with additional argument at the end of wp_enqueue_script,
By adding a “true” argument.. the script then will be loaded at the ‘footer’ part, or wherever in the themes file that having this line called.


I was exprementing with shashin plugin and changing these line in Shashin.php .

            // edited by .namran to add additional argument at the end of as "true"
            wp_enqueue_script('highslide_js', SHASHIN_DISPLAY_URL . '/highslide/highslide.js', false, '4.1.4',true);
            wp_enqueue_script('swfobject_js', SHASHIN_DISPLAY_URL . '/highslide/swfobject.js', false, '2.1',true);
            wp_enqueue_script('highslide_settings_js', SHASHIN_DISPLAY_URL . '/highslide_settings.js', false, SHASHIN_VERSION,true);

References :

1. http://lesterchan.net/wordpress/2009/01/26/loading-javascript-in-footer-in-wordpress-28/
2. http://developer.yahoo.com/performance/rules.html#js_bottom
3. http://wordpress.org/extend/plugins/shashin/

Namran Hussin:
Related Post
Leave a Comment