Optimizating the Speed of your Website - Speed Performance


Active Member
Hello fellows!

I'm writing this thread because a week ago I had to optimize my website after receiving 4 mails by my hosting company. They were about over usage of the server CPU. I've spent a few days on researching and I got some satisfaction from the results. My website now loads faster and this is thanks to a few optimizations on the server - Apache 2.0 - 2.2, Linux OZ.

All the steps are described below and they will save you from your future problems with bad hosting services. Your site will load faster too. I use the most effective basics and the thread is oriented to shared hosting users. You will need no more than 15 minutes.

First you have to test your page's loading speed with one of these tools:

Yahoo YSlow
Google Page Speed Insight

Lets get going!

Open your .htaccess file with any text editor - don't forget to create a copy in case something bad happens!

1. Enable file compression

Mod_deflate lets you compress your files. Find <ifmodule mod_deflate.c> .htaccess and replace it with this code:

<ifmodule mod_deflate.c>
## enable apache served files compression
## http://developer.yahoo.com/performance/rules.html#gzip
# Insert filter
SetOutputFilter DEFLATE
# Netscape 4.x has some problems...
BrowserMatch ^Mozilla/4 gzip-only-text/html
# Netscape 4.06-4.08 have some more problems
BrowserMatch ^Mozilla/4\.0[678] no-gzip
# MSIE masquerades as Netscape, but it is fine
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
# Don't compress images
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary
# Make sure proxies don't deliver the wrong content
Header append Vary User-Agent env=!dont-vary

In cPanel find "Programs and additional software" or something and chose the option "Optimize Website". After that click on "compress all content" Refer to the screenshots below.

Виж файлът 6034Виж файлът 6035

2. Turn on the mod_expires Apache module.

I've tested at least 10 variations, but this one gave me the best results.

Repeplace this code with the code below in the .htaccess file.

<ifmodule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 1 month"

with the code below in the .htaccess file.

<IfModule mod_expires.c>
	## Add default Expires header
	## http://developer.yahoo.com/performance/rules.html#expires
	ExpiresActive On
	ExpiresDefault "access plus 1 month"
	ExpiresByType image/jpg "access 1 month"
	ExpiresByType image/jpeg "access 1 month"
	ExpiresByType image/gif "access 1 month"
	ExpiresByType image/png "access 1 month"
	ExpiresByType text/css "access 1 month"
	ExpiresByType application/pdf "access 1 month"
	ExpiresByType text/x-javascript "access 1 month"
	ExpiresByType application/x-shockwave-flash "access 1 month"
	ExpiresByType image/x-icon "access 1 year"
	# Set Expires Headers
	<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
	Header set Cache-Control "public"
	Header set Expires "Tue, 14 Aug 2020 03:00:00 PST"
	<FilesMatch "\.(bmp|css|flv|gif|ico|jpg|jpeg|js|pdf|png|svg|swf|tif|tiff)$">
	Header set Last-Modified "Mon, 31 Jan 2011 00:00:00 GMT"
	# Set the cache-control max-age
	# 1 year
	<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|swf)$">
	Header set Cache-Control "max-age=31449600, public"
	# 2 DAYS
	<FilesMatch "\.(xml|js|css)$">
	Header set Cache-Control "max-age=604800, public, must-revalidate"

	# 4 HOURS
	<FilesMatch "\.(html|htm|txt)$">
	Header set Cache-Control "max-age=14400, must-revalidate"

3. Turn on the KeepAlives option. This increases the speed of loading of HTML pages with a lot of images.

KeepAlive On
KeepAliveTimeout 2

A few more tips. Ask the support of the hosting to install you a PHP accelerator like APC or XCache. I don't need to use any of them but keep it in mind.

Do a few test with the tools mentioned above and I hope you'll see better results.

Прикачени файлове

  • optimize-1.png
    38 KB · Преглеждания: 2
  • optimize-2.png
    13.9 KB · Преглеждания: 1
Последно редактирано от модератор:


Well-Known Member
Optimize Website Speed - Speed Up Your Site

I don't have experience with codes in .htaccess so I will ask you a few questions:

1. What were your results before and after doing these steps?

2. You said that you had problems with CPU usage - How much of it you used before and what you use now?

3. Are the codes above universal? (Hope to see a few pros get in here). I don't know is there a difference when you use this for a WordPress site and an OpenCart site for example?

If it is the same for all sites and if the results are good, this information will be very interesting. A site is always not fast enough. :)
Последно редактирано от модератор:


Active Member
Your questions are reasonable.

The improvements described above are for an Apache server no matter of the script which runs on it. In my case the CPU was reduced by 35%, but I want to say that It was really huge! I described only three improvements but they are usable on all scripts. If someone wants to optimize a WordPress site there are a lot more options available like a plugin that optimizes the caching process. I didn't describe every single thing I did because in my case I use Magento - a very heavy script that wants a lot of stuff. The speed measured by Google before the process was 68. Now it is 90. With YSlow it was 58, now it is 94.

Hope my answers are useful.
Последно редактирано от модератор:


Well-Known Member
Website Speed and Performance Optimization

Which is the best result on the Google test. What should I get as a result if I want to have my site good enough. I'm asking because not it shows 83-86 and I want to know whether I need to optimize it or not?
Последно редактирано от модератор:


Active Member
You can try to get it in the 92-96 range. The maximum is 100. It is good to navigate in a site that loads fast, just because of the functionality and the user experience.
Последно редактирано от модератор:


Active Member
I want to add something about Magento and I will use this topic. No need to create a new one.

1. Admin > System > Configuration > Catalog > Frontend

Option Use Flat Catalog Category - Choose YES
Option Use Flat Catalog Product - Choose YES
Option Allow Dynamic Media URLs in Products and Categories - Choose YES

Save changes.
2. Download the two files below:

a). magento-cleanup - decompress and put magento-cleanup.php in your root directory on the site. Then load in your browser this:


b). magento-check - do the same.

3. Изтеглете htaccess файла - decompress it and put it into your root directory.

4. Download and install Lazy Monkeys - a free app for fast loading of pictures by Ajax - category pages. Instructions for the installation can be found in the package after you decompress it. See the demo version. [/url

5. Open local.xml - app/etc/local.xml - Make a copy before editing it.

Replace [file] with [db] in session_save, like it is done below.



Delete the cache in var/cache

It's ready - Speedup!

If you have problems send me a PM and I will help you.
Последно редактирано от модератор:


New Member
Website Performance and Optimization Test

Thank you for this great tutorial. In the moment we have some problems with the CPU usage time too. A WordPress site with not visitors and a opencart e-shop which we still develop. This combination of scripts is pumping up the CPU to 500%. I will try this and hope it helps.
Последно редактирано от модератор:


Active Member
For wordpress I can recommend you to try this. It is mentioned in another thread in the forum, but never tried it personally.

It don't know how Magento works, but for Wordpress I managed to cut the CPU usage by caching the main page and the side bar with a simple script which I've found in this forum :
You can choose the time when your content or a chosen element will update. That way the content will not be downloaded by every user, they all will use something until the time comes for the update. No idea if this could be done in your case.

I can recommend you this caching plugin - http://wordpress.org/plugins/w3-total-cache/

For opencart look at this app - It costs 25$, but I think it will give you the needed results.
Последно редактирано от модератор:


Well-Known Member
Page Speed - Make the Web Faster

The topic made me look about OpenCart and here is what I found.

It is about smartoptimizer, which can be found in the archive, considering the thread in the opencart forum a few ideas came out. The reason is that a bigger part of the users rated negatively the whole thing. I will share an option which I've tested on a store with a few products. Didn't put any extensions that fasten the loading speed.

Those are my results before the optimizations:

Виж файлът 6043

Those are the results after the whole process:

Виж файлът 6044

This is the .htaccess code:
# 1.To use URL Alias you need to be running apache with mod_rewrite enabled.

# 2. In your opencart directory rename htaccess.txt to .htaccess.

Options +FollowSymlinks

<ifModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file \.(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*

# compress text, html, javascript, css, xml:
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
# Or, compress certain file types by extension:
<files *.html>
SetOutputFilter DEFLATE

<FilesMatch ".(js|css)$">
Header append Cache-Control "private"
<FilesMatch "\.(gif|jpe?g|png)$">
Header set Cache-Control "public"

<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 10 days"
ExpiresByType text/css "access plus 1 month"
ExpiresByType text/plain "access plus 1 month"
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType application/x-javascript "access plus 1 month"
ExpiresByType application/javascript "access plus 1 month"
ExpiresByType application/x-icon "access plus 1 year"

<IfModule mod_expires.c>
<FilesMatch "\.(gif|jpg|jpeg|png|swf|css|js|html?|xml|txt|ico)$">
ExpiresActive On
ExpiresDefault "access plus 10 years"
<IfModule mod_rewrite.c>
RewriteEngine On

#RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*\.(js|css))$ smartoptimizer/?$1

<IfModule mod_expires.c>
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.*\.(js|css|html?|xml|txt))$ smartoptimizer/?$1

<IfModule !mod_expires.c>
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.*\.(gif|jpg|jpeg|png|swf|css|js|html?|xml|txt|ico))$ smartoptimizer/?$1
<FilesMatch "\.(gif|jpg|jpeg|png|swf|css|js|html?|xml|txt|ico)$">
FileETag none

# SEO URL Settings
RewriteEngine On
# If your opencart installation does not run on the main web folder make sure you folder it does run in ie. / becomes /shop/

RewriteBase /
RewriteRule ^sitemap.xml$ index.php?route=feed/google_sitemap [L]
RewriteRule ^googlebase.xml$ index.php?route=feed/google_base [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]

Like I said, I don't know much about that, but these correction made my site fly. I think there are a lot more things to do. Hope others share some information, too.


Прикачени файлове

  • test_1.jpg
    33.6 KB · Преглеждания: 1
  • test_2.jpg
    21 KB · Преглеждания: 1
Последно редактирано от модератор:


Well-Known Member
Improve your website's performance

By turning on mod_deflate you will never decrease the CPU usage time..just the opposite - you will increase it. This only decrease the traffic between the server and the client.

This goes to the both our post right?
Последно редактирано от модератор:


Active Member
How Fast Is Your Site? Website Performance Monitoring

@lqllqlq download the .htaccess of my Magento website and see if you can get something for yours. I'm sure you can do a lot of things to your site to make it run better.

For open cart look a this:


It cost 25$ dollars, but for sure It will help you decrease CPU usage times.
Последно редактирано от модератор: