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.
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.
Try not to overcompensate because your site seems a bit sluggish.