Boost the speed of your Magento

79 Comments 30th JUN 2008 | Posted by Tomislav Bilic in Magento

Boost the speed of your 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

If you like what you read, please share it.

  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Yahoo! Bookmarks
  • Reddit
  • Technorati
  • Twitter
  • StumbleUpon
  • LinkedIn
  • Netvibes
  • NewsVine
  • Sphinn
  • Tumblr
  • Posterous

To post code in comments, place your code inside [code] and [/code] tags.

There are 79 comments (Add Yours +)

  • Wow, amazing how much this changes. It’s actually pretty fast now.

    Thanks for the advice!

    Cheerz, Casper.

  • You can also play with DeflateBufferSize and DeflateCompressionLevel settings. But don’t make DeflateCompressionLevel too high, though

  • Tomislav Bilic Says

    Thanks Vladimir,

    Can you please present the examples of such usage?

  • 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>

  • Tomislav Bilic Says

    Thank you :)

  • Hi!
    is this valid for *any* webhosting?

    thanks.
    -andres

  • Tomislav Bilic Says

    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.

  • Wow this works really well, thanks for the advice!

  • Amazing! Thank you!

  • my htaccess file already looks like that. i just d-loaded two days ago. am i missing something?

  • When I try this on Mosso clustered hosting I get a 500 Internal Server error

  • 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?

  • Thanks, fortunately it did help making magento run three times faster :)

  • Made a huge difference unreal

  • 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.

  • 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

  • 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

  • Thanks man! Works Great!

  • Fantastic! – Good call on uncommenting the zlib flag, XPC.

  • Id didn’t work for me, should it start working as soon as you modify the .htaccess? Did I miss another step?

  • thanks so much!!!!! it truly works much more faster than before!

  • @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.

  • thanks for the info Bilic…

    is this compatible with magento-1.2.0.3, also?

  • GREAT JOB
    ……yes it works with 1.2.0.3

  • Can someone cut and paste their htaccess file? Mine keeps giving me a 500 Internal Server Error when I add Vladimr’s suggestions

  • @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

  • 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

  • I did as the above instruction but no success. the site’s speed seems not changed anymore. I use magento 1.3.0

  • Great tip. Thanks!

  • didn’t help my site out.
    Magento 1.3.2.1
    hosted at Crucial Webhosting on a split-shared container.

  • 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!!

  • Worked fine for me thanks a lot

  • Very helpful,very good!

  • Nice one !! And thanks for your guidance.

  • Thank you for this nice and helpful article.

  • [...] 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/) [...]

  • way faster… it took several page loads to see the difference, but it is much better now. thanks!

  • 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

  • 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

  • This works. thank you

  • 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??

  • 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

  • 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?

  • 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/

  • Thanks Andy for your help, cheers

  • 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!!!

  • Wow! Magneto pages are now loading in less than a second! See http://www.itsournature.com/

  • Very helpful, i’m hosting site on godaddy Deluxe linux hosting.

  • 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

  • please alabore what lines should be changed in htaccess file

  • 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.

  • It got about 50% faster which is a big difference!

  • 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!

  • just turn cache off till you are ready to go live

  • Just halved my home page load speed with this… Awesome and thanks! I think it will translate into a reduced bounce rate too :)

  • Wow, it works!!!

    Thanks, man, i just thought magento couldn’t be more faster,

  • Thanks for the tip – it shaved a little bit off the load time.
    John

  • PrestaShop Core Team Says

    No, Bad method!!!!
    Not Speed Up~~~~~~~~Never……………….

  • 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! :D

  • mod_deflate is not included in common apache configuration.
    Is there any sense to compile apache with mod_deflate when Nginx installed?

  • Great Job… !

  • 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.

  • 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/

  • Hi,

    What should i change exactly? And does it work with Magento 1.4?

  • Brilliant!!! This has sped up my Magento store (both front end and admin panel) by nearly 180% :-D

  • 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

    ############################################

  • 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.

  • We’ve used this on our latest website: chinese-gadgets.nl. Feels a lot faster while browsing. Thanks!

  • Amazing! Worked like a charm
    Thanks a lot!

  • 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

  • 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

  • Hey , …

    Nice One …

    Works fine for me …

    Thanks ……………………..

  • 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/)

  • ouch!! that is really slow… what sort of server are you on? shared? vps?

  • 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?

  • Hi,

    thanks for sharing here and its work gr8

    thanks again

  • Thanks this has increased the site speed in Magento Ecommerce Website quite alot, I tested it using YSlow plugin for magento. Great Article

Leave a Comment

Please wrap all source codes with [code][/code] tags.
Magento Design and Development | Magento SEO | iPhone Application Development Web Application Development with ZEND | WordPress Ecommerce | WordPress development
Sitemap

Inchoo - webappsolutions | 2009