Login

WordPress SEO Optimization: Enable Gzip Encoding and Caching

Google has begun emphasizing the importance of how fast your website loads by including site loading speed as a ranking factor in their search engine. If your website loads slowly, you should take some steps to improve its loading time. This tutorial can help you speed up the loading time of your WordPress website by focusing on Gzip encoding and caching, the two most important factors for improving website loading time.

You can read the Google blog entry in which the company talks about using site speed as a web search ranking factor here.

Overview of Gzip Encoding and Caching

Before I discuss the detailed steps, you should know something about Gzip encoding and caching. Gzip encoding speeds up a website by compressing the content from the server to the client browser. This reduced file size is what speeds up loading. See the flowchart below:

Enabling gzip encoding requires you to have full access to your website files and source code. By default, your server and WordPress does not have gzip encoding enabled, so you need to tweak your website to enable it.

On the other hand, caching improves your website’s loading performance, particularly if you have a fairly large WordPress website. WordPress creates a dynamic website, which means it relies on both PHP and a MySQL database to serve content.

Refer to the diagram below for the differences between non-cached and cache- enabled WordPress websites:

If caching is enabled in WordPress using a plugin, it caches the WordPress content in advance and converts it to plain, static HTML files. This means there will be no need to execute PHP scripts and communicate to MySQL databases to fetch content.

So if there is a content request, WordPress automatically renders the cached, static HTML files to the client browser, thus improving both the server’s and website’s loading performance.

Heavy PHP script execution consumes a lot of CPU resources, and in a traffic spike situation (for example, if your website post gets featured in Digg), there is a strong chance your site will go down due to this problem.

With caching enabled, your WordPress website will be protected from this problem.

Enabling Gzip Encoding in WordPress

There are different ways to enable Gzip encoding in a WordPress website. These include using htaccess; using PHP; and using a WordPress plugin.

Not all web hosting servers have enabled the mod gzip directive in Apache. If your web host’s servers fall into this category, you cannot use the .htaccess method.

Also, some servers are sensitive to changes in .htaccess configuration. In this case, if you have enabled Gzip encoding via a WordPress plugin, it may not work, and will introduce some problems.

The best and easiest way to enable Gzip encoding in a WordPress website involves using PHP script. To make sure gzip encoding has been implemented correctly, follow the steps below:

Step 6. Try entering other WordPress URLs, for example post URLs, to find out if gzip encoding has been implemented sitewide. It should be enabled sitewide.

IMPORTANT: When upgrading your WordPress, the line you added, ob_start("ob_gzhandler"); will be removed from index.php. Therefore, you should manually add that line again after a WordPress upgrade to enable gzip encoding.

Step 11. Check “Test Cache.” There should be no errors reported. If none, proceed to the next step.

Step 12. Check “Preload mode…”

Step 13. Click the “Update Settings” button.

Step 14. Click the “Preload Cache now” button.

Step 15. Scroll down to the Mod Rewrite Rules section. Make sure this is updated; if you are in doubt, you can always click “Update Mod_Rewrite Rules” so that those lines will be added to your WordPress .htaccess. Details about this additional .htaccess syntax can be found here: http://wordpress.org/extend/plugins/wp-super-cache/installation/

That’s it. You do not need to enable compression since you already implemented it in the previous section. Just leave the items below at its default settings:

Cache contents

Super Cache compression (should be set to Disabled).

Expiry Time and garbage collection.

Accepted Filenames and Rejected URIs.

Rejected User Agents

Debug Settings

Lock down

Directory Cached Files

Fix Configuration

Cache plugins

The installation and configuration of the WordPress Super Cache plugin is complete. To confirm that you have successfully installed the Super Cache plugin, go to your home page and then view the HTML source code.

Go to the last portion of the HTML code. You should see a comment like this:

The most important point is that you should see the “Cached page generated by WP- Super-Cache.”

Important things you should know about enabling cache

Now that there is virtually no dependence on PHP script to generate and display content to your visitors if caching is enabled, you need to make some adjustments, particularly if you are updating the website with the following common tasks:

You might notice that even if you have new posts or update something on your WordPress website, your server won’t display the changes you have made. This is because it is still displaying the cached content (which is old and needs to be updated).