Home arrow PHP arrow Page 3 - Speed up Web Page Loading Using Google Page Speed

Page Loading Improvement Case Study - PHP

The easiest way to improve your website's conversions may have less to do with SEO and your content and more to do with how fast your pages load. Internet users have a short attention span, and won't wait for your pages to load when the next site is just a click away. Fortunately, you can fix your web page loading times with the help of Google Page Speed.

TABLE OF CONTENTS:
  1. Speed up Web Page Loading Using Google Page Speed
  2. Introduction to Google Page Speed
  3. Page Loading Improvement Case Study
  4. GZIP Compression for CSS Files
  5. Optimizing the Order of JavaScript and CSS
By: Codex-M
Rating: starstarstarstarstar / 6
February 01, 2010

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement
  

After analyzing the performance of the test website, http://www.php-developer.org , the following are the results: 

The red exclamation marks are serious problems. For the purpose of illustration, we will only tackle the most pressing problems/actions, which are enabling Gzip compression, and some JavaScript optimization tips like optimizing the order of styles and scripts.  

Enabling Gzip Compression. This works by compressing the output to the browser instead of sending the uncompressed file, which is heavy. See the illustration below:

 

 

If it is compressed, it will be retrieved very easily by the browser -- in short, the page loading time should improve. 

There are different ways to implement GZIP compression. It can be done either in .htaccess or PHP. For simplicity, we will implement GZIP compression using PHP to make the process easy to understand. 

There are basically three types of files that you need to compress for efficiency. These are HTML-related files, JavaScript files and CSS files. For illustration purposes, we will be using WordPress, since it accounts for the majority of the CMSs used; however, the principle discussed can be applied to any platform. To compress HTML, follow the steps below.  

Step 1: Log in to your WordPress FTP root directory and download index.php file (located at the WordPress root directory). 

Step 2: Using your favorite PHP editor, open the file and copy paste the code below to the top most part of the script:

 

if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) {

ob_start("ob_gzhandler");

}

else {

ob_start();

}

 

So that the new index.php will now be:

 

<?php

if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) {

ob_start("ob_gzhandler");

}

else {

ob_start();

}

/**

 * Front to the WordPress application. This file doesn't do anything, but loads

 * wp-blog-header.php which does and tells WordPress to load the theme.

 *

 * @package WordPress

 */

 

/**

 * Tells WordPress to load the WordPress theme and output it.

 *

 * @var bool

 */

define('WP_USE_THEMES', true);

 

/** Loads the WordPress Environment and Template */

require('./wp-blog-header.php');

?>

 

This code loads the call back function ob_start to facilitate sending gz-encoded data using PHP and compresses the content before sending it to the browser, which accepts gzip-encoded data. Save and upload it to the WordPress root directory. You can use this tool to make sure your compression is working. 



 
 
>>> More PHP Articles          >>> More By Codex-M
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: