Pages

Tuesday, October 25, 2011

Speed Up WordPress Page Loading Times By Removing l10n.js

I recently noticed that my WordPress blog’s page loading times increased through the roofs which made me reevaluate everything that contributed to the loading times of the website. I implemented a few changes on the blog to improve page loading times. I first got rid of the three social networking buttons pointing to Google Plus, Facebook and Twitter, and replaced them with the Add This script instead. The benefit here was that it reduced the external JavaScript code that needed to be loaded for the functionality from three to one.

I also noticed that articles with hundreds of comments were loading significantly slower than pages with less comments. This made me reduce the number of comments per page to 50 root comments (plus their answers).

Today I noticed that WordPress added another JavaScript to ever page. The script in wp-inlcudes/l10n.js that is related to the admin bar that the WordPress developers added to one of the recent versions of the blogging platform.

While it is a small file with a size of 233 bytes it is still a script that is loaded by anyone, not just the admin of the blog. This somehow does not make a lot of sense. The important thing here is that the blog needs to make the request to load the element, not the time it takes to load the 223 bytes.

ghacks page objects

WordPress administrators may want to remove the JavaScript element from being loaded by every blog visitor to speed up the blog’s page loading times. The easiest way to remove the l10n.js from being loaded with WordPress is to unload it in the functions.php file in the WordPress theme folder.

All you need to do for that is to add the following line of code to the end of the functions.php file.

wp_deregister_script('l10n');

Please note that this may disable part of the admin bars toolbar functionality. Users over at Stack Exchange have found a way to keep the JavaScript loaded for administrators of the blog.

if ( !is_admin() ) {
function my_init_method() {
wp_deregister_script( ‘l10n’ );
}
add_action(‘init’, ‘my_init_method’);
}

Just add this code instead to the functions.php file.


© Martin Brinkmann for gHacks Technology News | Latest Tech News, Software And Tutorials, 2011. | Permalink |
Add to del.icio.us, digg, facebook, reddit, twitter
Post tags: , , , ,



0 comments:

Post a Comment