Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I never really dug into the compression options I have for my plugins and themes, so here I am. I was reading a few articles about PHP compression like this one and I had a question.

Is it really as easy as adding the following code in the appropriate spot?

<?php
if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip'))
    ob_start("ob_gzhandler");
else
    ob_start();
?>

I definitely want to learn more about compression as we all know the benefits of it, but I am unsure exactly where to start. Any suggestions?

Are there better ways to effectively reduce the load time for my plugins and themes? It's not that I'm having a problem with a particular piece of code, I just would like to expand my knowledge on the subject.

I am speaking in terms of a plugin or theme that would be used by many people, so this compression process would (hopefully) be sort of 'automatic', without having the user mess with their server configuration.

share|improve this question
1  
This is not about compressing your PHP, it's about compressing the output of PHP. Therefore I don't recommend doing it in PHP, a much better way to do it in the webserver serving the content. For apache, search for deflate, for nginx, gzip is the keyword. –  petermolnar Jan 17 '12 at 13:26
    
@petermolnar My main concern is, will it be easy to implement that kind of thing "automagically" in my plugin so the end-user doesn't have to mess with their server configuration? –  Jared Jan 17 '12 at 13:29
    
But PHP is a lot slower on this topic. Also, if the server compression is enabled, double compressing would result a pretty large overhead. –  petermolnar Jan 17 '12 at 13:31
1  
@Jared separation of concerns. You provide the functionality without being stupid, let others handle how to deliver it efficiently. Also, always remember that gezipping takes time, as does connection initialisation (independent of how many you transfer). Compression only pays off for sufficiently large and compressible data. For me, the best speed improvement was achieved (besides caching) by enabling pipelining (both on server and client) and to configure the browser to start rendering while it still receives data. –  Raphael Jan 17 '12 at 20:24
    
That makes sense, I suppose I could be a bit over-paranoid of how my plugins are running, but then again I'm just looking for basic information. Thank you for your input. –  Jared Jan 18 '12 at 5:20

2 Answers 2

up vote 2 down vote accepted

To answer your question, yes, it is that easy to enable compression. However, that's only a small step when configuring a site for performance.

You should not attempt to handle compression from your plugin, unless the entire purpose of the plugin is load time optimization. Leave that to dedicated plugins, such as the WP Super-Cache or W3 Total Cache.

share|improve this answer

Try not to overcompensate because your site seems a bit sluggish.

  1. Run a performance test to figure out what issues your site really has
  2. Enabling GZIP in your webserver is probably a good idea
  3. Install a plugin such as WP Super Cache that handles caching, minifying and file script aggregation.
  4. Minimise the number of images each site contains, and make sure that small thumbnails are available (WP does that for you if you include images via the Add Media dialog).
  5. If you still have problems, try to disable suspicious plugins one by one. Many are badly written.
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.