Boost the speed of your Magento
79 Comments 30th JUN 2008 | Posted by Tomislav Bilic in Magento

One of the drawbacks of Magento is currently its speed if default configuration is used. There are certain ways of making it run faster. The best one is to enable GZip compression by changing .htaccess file a little. You just need to uncomment part of the code. In my case, the speed increase was exactly 235%. Let’s start speeding up Magento!
Find the following lines in your Magento .htaccess file and replace them with the following code.
############################################
## 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
# enable resulting html compression
php_flag zlib.output_compression on
To post code in comments, place your code inside [code] and [/code] tags.


















August 1st, 2008 at 14:53
Wow, amazing how much this changes. It’s actually pretty fast now.
Thanks for the advice!
Cheerz, Casper.
August 4th, 2008 at 19:25
You can also play with DeflateBufferSize and DeflateCompressionLevel settings. But don’t make DeflateCompressionLevel too high, though
August 12th, 2008 at 7:41
Thanks Vladimir,
Can you please present the examples of such usage?
August 12th, 2008 at 14:04
I did it this way (this is a part of <VirtualHost> declaration):
<IfModule mod_deflate.c>
DeflateBufferSize 32768
DeflateCompressionLevel 5
<Location />
SetOutputFilter DEFLATE
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png|tiff)$ no-gzip dont-vary
Header append Vary User-Agent env=!dont-vary
</Location>
</IfModule>
August 12th, 2008 at 14:51
Thank you
August 22nd, 2008 at 15:34
Hi!
is this valid for *any* webhosting?
thanks.
-andres
August 25th, 2008 at 21:11
Hi Andrés,
Most of the things don’t always work on all hostings. For example, I’m sure Vladimir’s suggestion is ok, but that doesn’t work on mine.
September 12th, 2008 at 22:12
Wow this works really well, thanks for the advice!
September 18th, 2008 at 14:19
Amazing! Thank you!
September 22nd, 2008 at 5:08
my htaccess file already looks like that. i just d-loaded two days ago. am i missing something?
September 28th, 2008 at 3:31
When I try this on Mosso clustered hosting I get a 500 Internal Server error
September 29th, 2008 at 4:06
i just tried using magento, but it’s way slow. where can i get the .htaccess file? the one i got off my server only has 3 lines in it about “order deny, allow Deny from all”
this isn’t the right file is it?
September 29th, 2008 at 21:46
Thanks, fortunately it did help making magento run three times faster
October 26th, 2008 at 10:50
Made a huge difference unreal
October 28th, 2008 at 20:16
What a difference far faster, i’m not 100% sure but this htaccess setup should work on any website!
AC-k3v, yes Magento v 1.1.6 has the coding in the htacess, however it is in a comment block and needs editing out.
November 7th, 2008 at 12:39
It depend if Apache is 1.3 or 2.0. I have Apache 1.3 and i have to use mod_gzip setting in htaccess:
mod_gzip_on Yes
November 12th, 2008 at 20:06
Someone posted a comment to my post (that refers to your solution) mentioning there’s another line of code that needs to be uncommented otherwise I don’t think these changes work.
############################################
## enable resulting html compression
php_flag zlib.output_compression on
December 16th, 2008 at 15:11
Thanks man! Works Great!
December 16th, 2008 at 22:15
Fantastic! – Good call on uncommenting the zlib flag, XPC.
December 18th, 2008 at 23:16
Id didn’t work for me, should it start working as soon as you modify the .htaccess? Did I miss another step?
December 21st, 2008 at 7:20
thanks so much!!!!! it truly works much more faster than before!
December 21st, 2008 at 12:04
@Aldo
Yes, it should start when you modify .htaccess file. If it doesn’t work, there could be several reasons, probably related to server configuration. Also, take a look at the comment from XPC Design to see if it helps.
Many thanks.
January 28th, 2009 at 18:40
thanks for the info Bilic…
is this compatible with magento-1.2.0.3, also?
January 28th, 2009 at 21:28
GREAT JOB
……yes it works with 1.2.0.3
February 7th, 2009 at 4:15
Can someone cut and paste their htaccess file? Mine keeps giving me a 500 Internal Server Error when I add Vladimr’s suggestions
February 10th, 2009 at 14:10
@Mark:
Commenting this out solved the 500 here:
# Make sure proxies don’t deliver the wrong content
# Header append Vary User-Agent env=!dont-vary
April 7th, 2009 at 3:13
Nice maybe I’ll start my own “fast” $20-$50 / month web hosting company with this, it improved my speed by at least 10,000% on a $3 / month web host….no joke
April 7th, 2009 at 15:06
I did as the above instruction but no success. the site’s speed seems not changed anymore. I use magento 1.3.0
April 8th, 2009 at 14:54
Great tip. Thanks!
June 2nd, 2009 at 21:18
didn’t help my site out.
Magento 1.3.2.1
hosted at Crucial Webhosting on a split-shared container.
June 20th, 2009 at 16:50
Just did this on my dedicated linux vm @ GoDaddy and my time to first byte went from ~40sec to 1.5sec-6sec.
HUGE IMPROVEMENT!! THANK YOU!!
June 29th, 2009 at 22:06
Worked fine for me thanks a lot
July 16th, 2009 at 16:32
Very helpful,very good!
September 10th, 2009 at 7:51
Nice one !! And thanks for your guidance.
September 12th, 2009 at 4:14
Thank you for this nice and helpful article.
September 12th, 2009 at 13:08
[...] 1) First and foremost ensure you have a fast hosting setup as Magento does tend to be resource heavy and will slow down or even crash a lot of shared hosting environments.2) If your using Firefox install YSlow and Firebug which are great tools for web developers and help to debug certain issues in websites and run YSLOW to determine where the bottlenecks and slow.3) Make use of MySQL’s caching feature by enabling cache on your query’s providing your hosting is capable of it (ask your web developer to do this as you may break/bring down your database).4) Tweak your apache configuration to change the values of max/min servers to ensure that the load placed on apache is handled better for this heavy ecommerce system5) Modify your htaccess file to enable GZIP compression of your site files which will compress the pages being sent to the browser and unzip them as they arrive meaning the size of your pages are vastly reduced (sometimes even by up to 80%!) (http://inchoo.net/ecommerce/magento/boost-the-speed-of-your-magento/) [...]
September 22nd, 2009 at 4:26
way faster… it took several page loads to see the difference, but it is much better now. thanks!
October 3rd, 2009 at 6:17
i tried many examples. But couldn’t able to find the correct solution to make the magento site speedup.
Check my website at http://www.theplrmart.com which is running slowly.
can anyone kindly help me out in getting the site fast please
Regards
Venkat
October 20th, 2009 at 16:06
Hi PLR Mart
I got exactly the same problem. Seems to stall during the initializiation.
Have you enable the profiler to see where it hangs in your case?
Regards
Fred
October 28th, 2009 at 14:25
This works. thank you
November 25th, 2009 at 9:15
I added this to my install, tried all the different uncomments, and I still receive a Internal Server Error (500). The only way I’ve been able to get this to go away is to uncomment
# enable resulting html compression
php_flag zlib.output_compression on
Which I’m sure is needed….
Any input??
December 12th, 2009 at 9:55
This is a great site.. thanks for providing all these lovely hints and tips… this one reminded me that i forget to set compression on one of my sites. doh!
the other 2 big things that made a difference for me was the installation of xcache and adding /var/cache to tmpfs
doing a apache benchmark 3000 times on the site after adding xcache to 1.8 seconds a drop from 11.3ish
hope this helps
December 15th, 2009 at 12:03
Thanks for the tutorial its made a big difference as far as I can tell. I would like to double test it via some type of website speed checker though just to be sure. Could any one recommend a good one?
December 15th, 2009 at 12:49
I use this one
http://www.freespeedtest.com/
gives a general idea of speeds from different parts of the world. or if you are offering hosting you could look at http://magebenchmark.sonassi.com/
December 15th, 2009 at 14:05
Thanks Andy for your help, cheers
January 6th, 2010 at 0:41
Wow!!! I tested my sites speed at http://www.freespeedtest.com before I did the .htaccess update:
Before: 16.34 seconds
After: 2.27 seconds
Amazing thanks!!!
January 9th, 2010 at 20:42
Wow! Magneto pages are now loading in less than a second! See http://www.itsournature.com/
January 10th, 2010 at 17:00
Very helpful, i’m hosting site on godaddy Deluxe linux hosting.
January 13th, 2010 at 8:31
Can someone take a look at my htaccess and tell me how to make the seed mods to it. everytime I try I get the 500 Internal Server error
Thanks
############################################
## uncomment these lines for CGI mode
## make sure to specify the correct cgi php binary file name
## it might be /cgi-bin/php-cgi
# Action php5-cgi /cgi-bin/php5-cgi
# AddHandler php5-cgi .php
############################################
## GoDaddy specific options
# Options -MultiViews
## you might also need to add this line to php.ini
## cgi.fix_pathinfo = 1
## if it still doesn’t work, rename php.ini to php5.ini
############################################
## this line is specific for 1and1 hosting
#AddType x-mapp-php5 .php
#AddHandler x-mapp-php5 .php
############################################
## default index file
DirectoryIndex index.php
## http://developer.yahoo.com/performance/rules.html#gzip
# Insert filter on all content
SetOutputFilter DEFLATE
# Insert filter on selected content types only
#AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript
# 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
############################################
## enable rewrites
Options +FollowSymLinks
RewriteEngine on
############################################
## you can put here your magento root folder
## path relative to web root
#RewriteBase /magento/
############################################
## workaround for HTTP authorization
## in CGI environment
RewriteRule .* – [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
############################################
## always send 404 on missing files in these folders
RewriteCond %{REQUEST_URI} !^/(media|skin|js)/
############################################
## never rewrite for existing files, directories and links
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
############################################
## rewrite everything else to index.php
RewriteRule .* index.php [L]
</IfModule>
############################################
## Prevent character encoding issues from server overrides
## If you still have problems, use the second line instead
# AddDefaultCharset Off
#AddDefaultCharset UTF-8
<IfModule mod_expires.c>
############################################
## Add default Expires header
## http://developer.yahoo.com/performance/rules.html#expires
ExpiresDefault "access plus 1 year"
</IfModule>
############################################
## By default allow all access
Order allow,deny
Allow from all
############################################
## If running in cluster environment, uncomment this
## http://developer.yahoo.com/performance/rules.html#etags
#FileETag none
February 15th, 2010 at 11:48
please alabore what lines should be changed in htaccess file
February 19th, 2010 at 8:00
My site is also very slow, please help me to solve this issue. I am using godaddy as hosting server and this is mostly accessed in Holland.
February 19th, 2010 at 20:50
It got about 50% faster which is a big difference!
February 19th, 2010 at 21:15
If the site is still in development will this affect the caching at all? Is this something you should do after launch or is it okay to do it in dev?
Looking forward to trying this. And thank you!
February 19th, 2010 at 23:54
just turn cache off till you are ready to go live
March 3rd, 2010 at 13:01
Just halved my home page load speed with this… Awesome and thanks! I think it will translate into a reduced bounce rate too
March 7th, 2010 at 12:38
Wow, it works!!!
Thanks, man, i just thought magento couldn’t be more faster,
March 27th, 2010 at 15:05
Thanks for the tip – it shaved a little bit off the load time.
John
April 9th, 2010 at 11:08
No, Bad method!!!!
Not Speed Up~~~~~~~~Never……………….
April 13th, 2010 at 15:31
Here is my version used on production:
AddOutputFilterByType DEFLATE text/html text/plain text/css text/xml application/x-javascript application/x-json application/x-httpd-php
AddOutputFilter DEFLATE html xml css js php
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
Header append Vary User-Agent
Cheers!
April 13th, 2010 at 21:40
mod_deflate is not included in common apache configuration.
Is there any sense to compile apache with mod_deflate when Nginx installed?
April 13th, 2010 at 22:31
Great Job… !
April 14th, 2010 at 9:03
One thing missed and that a lot of people cry about on shared hosting is that HTTP compression is usually disabled permanently and the .htaccess enablement for HTTP Compression doesn’t work.
This method doesn’t do your .css and .js files etc, but it does do every page in your store.
Edit your index.php and add the following line at the very top on its own line.
However do NOT use this method along with the .htaccess file method.
Hope it helps those with Magento and 1and1 Internet etc.
Rob.
April 14th, 2010 at 9:04
Oh it looks like it didn’t post due to a filter.
I will try escape it with two \\
\\
If you still cant see the line above then read…
whatsmyip.org/http_compression/phpgzip/
April 24th, 2010 at 23:41
Hi,
What should i change exactly? And does it work with Magento 1.4?
May 4th, 2010 at 18:41
Brilliant!!! This has sped up my Magento store (both front end and admin panel) by nearly 180%
May 6th, 2010 at 4:34
some one please help me, its not working for me
my site is loading in 5-7 sec
i know i did the right change in .htaccess
############################################
## enable apache served files compression
## http://developer.yahoo.com/performance/rules.html#gzip
# Insert filter on all content
SetOutputFilter DEFLATE
# Insert filter on selected content types only
#AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript
# 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
# enable resulting html compression
php_flag zlib.output_compression on
############################################
May 6th, 2010 at 4:37
here’s my site url (http://www.urbaninstyle.com/magento/)
May 11th, 2010 at 2:48
Tomislav – thanks so much for this one! Big boost on all our sites. Thanks again.
carlos – seems like your site may have some settings incorrect with your host? Super slow. Where is it hosted? Have you tweaked the php files per the many posts out there – really helped our sites. Good luck.
May 11th, 2010 at 16:15
We’ve used this on our latest website: chinese-gadgets.nl. Feels a lot faster while browsing. Thanks!
May 20th, 2010 at 13:49
Amazing! Worked like a charm
Thanks a lot!
June 1st, 2010 at 21:18
I had the same problem. after following all the advices above , i came across this:
# enable resulting html compression
# For security reasons, mod_php is not used on this server. Use a php.ini file for php directives
#php_flag zlib.output_compression on
My host is bluehost.
So in ~public_html/php.ini , change this line:
zlib.output_compression = off
to
zlib.output_compression = on
Now it is super fast.
Thank you all
June 2nd, 2010 at 11:54
[...] Enable Gzip Compression in htaccess [...]
June 21st, 2010 at 17:18
We have developed a Magento page caching module that reduces page response times to lower than half a second. You can see our module working at zumiez.com and redmarblesteaks.com
Check us out at http://store.delorumcommerce.com
July 5th, 2010 at 13:20
Hey , …
Nice One …
Works fine for me …
Thanks ……………………..
July 15th, 2010 at 3:13
hello, I have made it with your method in my magento1.4, but the speed Without change,why?
here’s my site (http://www.greatreplicasell.com/)
July 15th, 2010 at 17:57
ouch!! that is really slow… what sort of server are you on? shared? vps?
July 23rd, 2010 at 11:27
Hi,
I’ve just enabled the Gzip on the server (win 2003 standard with iis 6).
Now, i have confirmed that the server as the Gzip activated with the test to a domain in the same server but when i try to test it on the Magento domain…it inst activated.
Test Tool
http://www.whatsmyip.org/http_compression/
Domain in the same server
http://directo.tr2k.com/login.aspx
Domain with MAGENTO
http://www.rockartstore.com/index.php/
The .htaccess doest work on IIS so that’s not a solution…iv tried in the php.ini only seems to work on Apache.
Any suggestions?
Is there a place were i can enable it in the admin panel?
August 16th, 2010 at 13:21
Hi,
thanks for sharing here and its work gr8
thanks again
September 1st, 2010 at 10:38
Thanks this has increased the site speed in Magento Ecommerce Website quite alot, I tested it using YSlow plugin for magento. Great Article