[METHOD] How To Optimize Your Page Speed ?

HostStage

Elite Member
Joined
May 20, 2010
Messages
2,083
Reaction score
1,836
Hey Guys,

Today, i'm going to cover a critical aspect of on page SEO. Hang On it will be long and not necessary exhaustive.

Page Speed is very important for 2 reasons :

- It helps Google to crawl further your website which is good for indexing of course
- It reduces your bounce rate or worse your pogosticking as your website is loading very slowly.

NB : Pogosticking = when a user goes to your website, goes back, picks another website and stay at your competitor. G. Panda take it as a factor of quality and you can now get outranked because of it.


Here are the tips :


1) The first thing to do is to used a golden tool which is the google page speed plugin :


For firefox users you have to use a plugin named firebug which is just great !

Once you have set it up properly, run a page speed test on your website. And try to match the orange, and red spot titles with this how to.


2) Enable Gzip if your web hosting provider allows it. Add this line at the top of your websites :


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


Then you can check if it is enabled here :



3) Compress your images. This is easy a bit boring but it increases drastically your loading time.

For that you can use either photoshop, The Gimp (free) or what i use personnally as i find it convenient the Google Page Speed plugin itself.
As it is showing you which images are optimized and which are not and allow to compress them with the save as button.

4) Open / Create a .htaccess file and place this code :

<IfModule mod_headers.c>
<FilesMatch "\.(js|css|xml|gz)$">
Header append Vary Accept-Encoding
</FilesMatch>
<FilesMatch "\\.(ico|jpe?g|png|gif|swf)$">
Header set Cache-Control "max-age=2592000, public"
</FilesMatch>
<FilesMatch "\\.(css)$">
Header set Cache-Control "max-age=604800, public"
</FilesMatch>
<FilesMatch "\\.(js)$">
Header set Cache-Control "max-age=216000, private"
</FilesMatch>
<FilesMatch "\\.(x?html?|php)$">
Header set Cache-Control "max-age=600, private, must-revalidate"
</FilesMatch>
</IfModule>

## Expire headers
<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 7200 seconds"
ExpiresByType image/jpg "access plus 2592000 seconds"
ExpiresByType image/jpeg "access plus 2592000 seconds"
ExpiresByType image/png "access plus 2592000 seconds"
ExpiresByType image/gif "access plus 2592000 seconds"
AddType image/x-icon .ico
ExpiresByType image/ico "access plus 2592000 seconds"
ExpiresByType image/icon "access plus 2592000 seconds"
ExpiresByType image/x-icon "access plus 2592000 seconds"
ExpiresByType text/css "access plus 2592000 seconds"
ExpiresByType text/javascript "access plus 2592000 seconds"
ExpiresByType text/html "access plus 7200 seconds"
ExpiresByType application/xhtml+xml "access plus 7200 seconds"
ExpiresByType application/javascript A259200
ExpiresByType application/x-javascript "access plus 2592000 seconds"
ExpiresByType application/x-shockwave-flash "access plus 2592000 seconds"
</IfModule>

# MOD_DEFLATE COMPRESSION
SetOutputFilter DEFLATE
AddOutputFilterByType DEFLATE text/html text/css text/plain text/xml application/x-javascript application/x-httpd-php
#Pour les navigateurs incompatibles
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html

SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip


Header append Vary User-Agent env=!dont-vary

# protect the htaccess file
<files .htaccess>
order allow,deny
deny from all
</files>

This will litteraly do some magic. If you have problem with the Gzip code stated above you can paste the full content. If you don't have problem with it you can remove this :

# MOD_DEFLATE COMPRESSION
SetOutputFilter DEFLATE
AddOutputFilterByType DEFLATE text/html text/css text/plain text/xml application/x-javascript application/x-httpd-php
#Pour les navigateurs incompatibles
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip

5) Place your javascript ressources at the bottom of your page. Personnally i don't do it, as i like to have my header with everything in it. But it will definitly help

6) Another thing i don't do because i go quite often in the code of my website, but you can remove the blank space of every file of your website, it will reduce the size of your pages by 10-25% according the lenght. You could do it for CSS code too.

7) Optimize your SQL databases the more often you can according to your traffic, through PHPmyadmin or through your CMS. This will bring you a light improvement and prevent you for unexpected crash.

Wordpress Users :

1) If you use wordpress you have to use a caching plugin like supercache or hypercache, it will drastically help with your loading time. You can earn something like 800% of your loading time with such a plugin according to some benchmarks :

Here is the place to find Super Cache :



To Go Further :

To be honest i don't do these as it is time killing when you have a website already and it makes you earn between 2 and 5 points in G speed :

1) Use CSS Sprites : The concept is to merge all your website's structural images into 1 mockup, then use the CSS to place the others elements into your mockup.
2) Use External Subdomain to load your external ressources (Javascript for exemple). It will allow you to use the speed of 2 servers instead of 1 to load your content


I believe there are others criterias i may have omitted but this is a good basis to drastically increase your loading time. It is an open thread, so go ahead with your own methods.
 
WoW!

Sweet Post, very detailed ... I learned a few tricks!

Thanks + rep given.
 
is wp super cache the same as w3 total cache or a complement ?
 
One of sites takes 7.9 seconds to load and I can not bring it down no matter what i tried, I will def try some of these tips, thanks
 
Hi mate, sorry to bother but all my sites are made in Joomla, below you can see my htacess file, can you tell me were to add the code??

##
# version $Id: htaccess.txt 21064 2011-04-03 2219Z dextercowley $
# package Joomla
# copyright Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved.
# license GNU/GPL
# Joomla! is Free Software
##


#####################################################
# READ THIS COMPLETELY IF YOU CHOOSE TO USE THIS FILE
#
# The line just below this section: 'Options +FollowSymLinks' may cause problems
# with some server configurations. It is required for use of mod_rewrite, but may already
# be set by your server administrator in a way that dissallows changing it in
# your .htaccess file. If using it causes your server to error out, comment it out (add # to
# beginning of line), reload your site in your browser and test your sef url's. If they work,
# it has been set by your server administrator and you do not need it set here.
#
#####################################################

## Can be commented out if causes errors, see notes above.
Options +FollowSymLinks

#
# mod_rewrite in use

RewriteEngine On

########## Begin - Rewrite rules to block out some common exploits
## If you experience problems on your site block out the operations listed below
## This attempts to block the most common type of exploit `attempts` to Joomla!
#
## Deny access to extension xml files (uncomment out to activate)
#<Files ~ "\.xml$">
#Order allow,deny
#Deny from all
#Satisfy all
#</Files>
## End of deny access to extension xml files
# Block out any script trying to set a mosConfig value through the URL
RewriteCond %{QUERY_STRING} mosConfig_[a-zA-Z_]{1,21}(=|\%3D) [OR]
# Block out any script trying to base64_encode data within the URL
RewriteCond %{QUERY_STRING} base64_encode[^(]*\([^)]*\) [OR]
# Block out any script that includes a <script> tag in URL
RewriteCond %{QUERY_STRING} (<|%3C)([^s]*s)+cript.*(>|%3E) [NC,OR]
# Block out any script trying to set a PHP GLOBALS variable via URL
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
# Block out any script trying to modify a _REQUEST variable via URL
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
# Return 403 Forbidden header and show the content of the root homepage
RewriteRule .* index.php [F]
#
########## End - Rewrite rules to block out some common exploits


########## Begin - Custom redirects
#
# If you need to redirect some pages, or set a canonical non-www to
# www redirect (or vice versa), place that code here. Ensure those
# redirects use the correct RewriteRule syntax and the [R=301,L] flags.
#
########## End - Custom redirects


# Uncomment following line if your webserver's URL
# is not directly related to physical file paths.
# Update Your Joomla! Directory (just / for root)

# RewriteBase /


########## Begin - Joomla! core SEF Section
#
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
#
# If the requested path and file is not /index.php and the request
# has not already been internally rewritten to the index.php script
RewriteCond %{REQUEST_URI} !^/index\.php
# and the request is for root, or for an extensionless URL, or the
# requested URL ends with one of the listed extensions
RewriteCond %{REQUEST_URI} (/[^.]*|\.(php|html?|feed|pdf|raw))$ [NC]
# and the requested path and file doesn't directly match a physical file
RewriteCond %{REQUEST_FILENAME} !-f
# and the requested path and file doesn't directly match a physical folder
RewriteCond %{REQUEST_FILENAME} !-d
# internally rewrite the request to the index.php script
RewriteRule .* index.php [L]
#
########## End - Joomla! core SEF Section
Thanks and rep given
 
@brseo you can place at the bottom of your file it will work perfectly :)
 
WP Super Cache is the best plugin I've ever tried. It's easy to use and you can load your web in less than 1/2 time.
 
Hi abysse,
I follow your guide,add the code,use gzip test tool,it show yes,but when I test the page speed,it show no gzip,still red color,what's wrong?can you help?thank you.

 
@judy i may need the URL of your website to have a closer look and the name of your hosting provider. Send me a PM.

At first glance i would say it comes either from your provider, or you didn't refresh the page speed module :)

You can try to clear your cache too from your browser.
 
Page speed is very important, and not only for Google but also for your visitors.
It's optimization really depends on the website structure itself: does it allow plugins? are there too many plugins? which plugin takes the more time to load? is the cache optimized? is the website too heavy? is the server optimized? is the server fast enough? are the pages compressed?
Theses are some of the questions you need to ask yourself. It is really a big challenge sometimes to take a ~3seconds loading site down to 0.5sec (from a regular ADSL connection), and it takes a lot of time. But when you're done, then it's magic :)
 
If any of you guys are using Magento and have not set up memcache on your box, give it a shot
 
Back
Top