Wednesday, February 16, 2011

How I speed up my WordPress blog | Speed up your blog


I thought I’d impart some tips on how I cut down the loading time for my blog. These tips might help someone out there make their WordPress blog (or any website) run closer. So far, using these techniques, I’ve shiny on top about 2 seconds off the loading time (when reserve is empty) and for repeat visitors, the load time is under 7 seconds. Hard performed using OctaGate SiteTimer. As typical, FireFox and Safari browsers were much closer than Internet Surveyor.

Compact (“minify”) your CSS, PHP, JavaScript (JS) and HTML Files

Removing whitespace, unnecessary shape, and useless code from these files will shrink file size, improving download time of these files, at the expense of (possibly) building the files slightly less legible. This is the simplest business you can do with these files. There are even online “compressors” everywhere you can upload or cut and paste your code, and it will spit out the compressed version, but I wouldn’t use that except you know the productivity. Observably, it helps greatly if you know CSS, PHP and so on, so you can edit and compact the code yourself.
Take out comments and commented code from your committed files and paste them into community backup files. I keep them on my hard handbook, everywhere I can make notes on what they’re for, in case I do eventually need them. Some CSS files even have whitespace (empty spaces) at the end of the line. If you press the “End” key, you can see everywhere the right end-of-line is, and backspace over it to take out the atrophied space.
And as I’ve found the hard way, WordPress will still process code surrounded by comments, even as leaving it commented out. So commented code (mainly with PHP or list calls) will needlessly waste processor time which could be used to sight your webpage. Weigh the benefits of keeping commented code in your blog’s PHP files versus removing it to fall file size and save processor cycles. Again, I take out unused code, comment it, and save it on my hard handbook if looked-for before long.
Google has an brilliant Firefox addon called PageSpeed which can show you everywhere your CSS is inefficient or unused.
See 10 Tips For A Smaller CSS File for specific examples of how you can shrink your CSS file.
Many PHP-based themes for WordPress also use comments and whitespace in surplus. Removing the whitespace and concatenating shape everywhere doable will result in smaller file sizes.
Your blog may also financial support from conditional includes, which will have the dual financial support of shrinking your file size and providing dynamic make fortunate. The process is like peas in a pod to the process for making open-air JS files: contain a link to the PHP file, and in that PHP file, take out the notch and closing PHP tags. Make it conditional by using if statements.

Go CSS to the top, and JS to the underneath

Page load time will also financial support if you go CSS associations to the top of the page, and JS associations to the underneath. Anyhow, this is what Yahoo recommends in their webpage optimization guidelines. JavaScript that isn’t essential for the surgical procedure of the page (ex: visitor tracking code) must be placed in the footer or at the underneath of the page, so the main make fortunate can load first. If you run WordPress, this is simple; there are a few “go Javascript to footer” plugins. 
JavaScript must also be externalized, to shrink overall HTML file size. See Lower The Size Of Your HEAD and scroll middle down for instructions on how to start open-air JS files.

Take out unnecessary Plugins, and make the remaining ones conditional

Are you using 10, 20, 30+ plugins? Some plugins are processed every time a page is loaded, even if they don’t in fact do no matter what business on that page. For develop, some plugins hook into the wp_head gathering to place CSS or JS associations in your header, which will be loaded on every page even if the plugin isn’t being used on that page.
Can you take out them, or find a “rollup” plugin that can do the work of two or three of your existing plugins?
A ordinary class of plugins for WordPress are the ones that interact with Google Analytics. This plugin involuntarily inserts your Google tracking code into your posts and pages. But I can duplicate the try by austerely pasting in Google’s tracking code frankly into footer.php of my theme, so saving time having the plugin do it. Just go to your Google Analytics tab and get the tracking code, and paste it into the PHP file. Sure, I might have lost some of the functionality of the plugin, but all I really need is the basic exposure gathering of my Analytics tab.
A additional ordinary plugin is Feedburner FeedSmith. This plugin detects all of the ways your feeds can be accessed, and redirects them to your Feedburner feeds. That way, you can entire sum all your subscribers under the FB feed, building your subscriber count more accurate, and building sure all your subscribers are seeing the same make fortunate.
But all I had to do to get rid of this plugin is visit  What is My WordPress Feed URL? and then edit my .htaccess file to redirect the built-in WP feeds to my FeedBurner feed.
Redirect 301 /blog/feed/ http://feeds.feedburner.com/MyFeedName
Redirect 301 /blog/feed/rss2/ http://feeds.feedburner.com/MyFeedName
Redirect 301 /blog/feed/rss/ http://feeds.feedburner.com/MyFeedName
and so on.
I got rid of the Random Posts plugin by using code I found on the ‘net that returns random posts using a WordPress gathering.
I am also using the Akin Posts plugin (from the same author) in my post footer, and if I didn’t mind changing it to random posts as a substitution for, I could use the above code as well, and take out two plugins.
Check your plugins and see if any of them don’t need to run all the time. For develop, if you run a plugin that allows visitors to email or photograph a copy of a post (ex: WP-EMail, WP-Photograph), you doubtless don’t need them to run if the visitor isn’t on a post page. Make them conditional as a substitution for. This sometimes requires supervise over editing of the plugin code itself.
  1. Deactivate the plugin
  2. Click the “Edit” link to edit the plugin file itself
  3. Wrap the entire plugin in an if proclamation that checks the current page. Don’t forget the notch and closing braces “{ }”
  4. Save the file and reactivate the plugin.
This will be most successful with plugins that write CSS or JS associations surrounded by your head tag, because this hack will stop them from doing so, so decreasing load time for pages everywhere the plugin isn’t de rigueur. If you got a serious error when editing/reactivating, or your blog breaks, or the fix austerely doesn’t work, you might need to quest the plugin file (deactivate it again first) and look for the section everywhere the CSS or JS file is written, and add the above code there as a substitution for.
Once editing is refined, the plugin will only run everywhere we want it. See WordPress Conditional Tags for a exact listing of conditional tags. Dredge up, you’ll need to repeat these steps every time a plugin is updated, because the hack will be wiped out by the update. It will be simplest if you deactivate the plugin, update it, then hack it, before reactivating it. Also, for persons plugins you need to call manually in your pattern, you’ll want to go through your pattern files and wrap the gathering calls in an ‘if (function_exists(plugin_name))’ proclamation, because you’ll be deactivating it a lot and you don’t want your blog to break every time you need to update a plugin. In fact, I urge you do this for all plugin gathering calls, even the ones you won’t be editing, because someday you might need to deactivate one.
Fastidious plugins don’t need to be running nearly the clock, and can be steadily deactivated and reactivated when looked-for. For develop, I keep the following plugins deactivated in anticipation of I need them:
  • WordPress List Backup
  • WordPress Compulsory Upgrade
  • Optimize DB
  • Maintenance Mode
Although it might in fact be better to take out them completely and reinstall them when looked-for, in view of the fact that all plugins (even deactivated ones) are check to see if they apply to a current page. Very inefficient on the part of WordPress, but that’s the way it is, and this is an condition about speed and optimization with all.