Boost the speed of your Magento

boost-magneto-speed © http://www.sxc.hu/photo/1098526

One of the drawbacks of Magento is currently its speed if default configuration is used. There are certain ways of making it run faster.
Let’s start speeding up Magento!


First step, edit .htaccess file.

Enable Output Compression

This section will turn on the apache mod_deflate module, which compresses text, css, and javascript before it is sent to the browser. This results in a smaller download size. To enable, simply uncomment the appropriate lines so that it looks like the following:

############################################
## 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 application/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 Expires Headers

Browsers use Expires headers to determine how long a page component can be cached. Static components, like images, should have far-future expires headers, but truthfully, all page components should have expires headers. To turn this feature on, just uncomment the appropriate line and add “ExpiresActive On” right above it. See below:

############################################
## Add default Expires header
## http://developer.yahoo.com/performance/rules.html#expires
 
    ExpiresActive On
    ExpiresDefault "access plus 1 year"

Keep in mind, if you use a far future Expires header you have to change the component’s filename whenever the component changes. More info http://developer.yahoo.com/performance/rules.html

Disable ETags

ETags are a way for browsers to validate cached components across subsequent visits. They can slow down a site served from a cluster if the cluster hasn’t implemented them properly. It is best to just turn them off as follows:

############################################
## If running in cluster environment, uncomment this
## http://developer.yahoo.com/performance/rules.html#etags
 
    FileETag none

Now, from Magento admin side make sure that you combine JS and CSS files.

  • Magento admin -> System Configuration -> Developer -> Under “Javascript Settings”, change “Merge Javascript Files” to YES.
  • Magento admin -> System Configuration -> Developer -> Under “CSS Settings”, change “Merge CSS Files” to YES

Clear the cache.

Use CDN if it is possible, please note combining CSS/JS when using CDN will cause CSS/JS to “break” until the CDN updates completely.

Enable Flat Catalog

Magento uses the EAV model to store customer and product data. This enables these objects to be incredibly extensible, but results in longer SQL queries and more reads. Enabling the Flat Catalog for Categories and Products merges product data into one table, thereby improving performance. Generally, all stores should enable Flat Catalog for Categories.

More information you can find following yslow user guide http://yslow.org/user-guide/, here you can find more tutorials and resources to follow.

Happy speeding :-)

If you need any help, we can do a Technical Magento Audit for your site.

Interested in hiring us?

Have a chat with us. You would be surprised how small changes can make your business even more successful.


About Stanislav Mihic

Frontend Developer

Stanislav is specialized in Web and Frontend Development with technologies such as JavaScript, CSS, and HTML using agile practices.

Read more posts by Stanislav / Visit Stanislav's profile

139 comments

  1. Thanks Dude. It really works, I followed all steps and it makes my site really fast. I checked on Google Pagespeed tool and Manually check the speed and found it really fast. But Still on 75/100 on Desktop and 60/100 on Phone. Please tell me how I can make it bit fast on Phone as well.

    Thanks in Advance.

  2. My htaccess file doesn’t have any of the code you mentioned above.What it has is given below.If there is any suggestion for me then please let me know.My website is running very slow..

    #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

    #End Gzip

    mod_gzip_on Yes
    mod_gzip_dechunk Yes
    mod_gzip_keep_workfiles No
    mod_gzip_can_negotiate Yes
    mod_gzip_add_header_count Yes
    mod_gzip_send_vary Yes
    mod_gzip_command_version ‘/mod_gzip_status’
    mod_gzip_min_http 1000
    mod_gzip_minimum_file_size 300
    mod_gzip_maximum_file_size 512000
    mod_gzip_maximum_inmem_size 60000
    mod_gzip_handle_methods GET POST
    mod_gzip_temp_dir /tmp
    mod_gzip_item_include file \.html$
    mod_gzip_item_include file \.php$
    mod_gzip_item_include file \.pl$
    mod_gzip_item_include file \.rb$
    mod_gzip_item_include file \.py$
    mod_gzip_item_include file \.cgi$
    mod_gzip_item_include file \.css$
    mod_gzip_item_include file \.js$
    mod_gzip_item_include mime ^application/javascript$
    mod_gzip_item_include mime ^application/x-javascript$
    mod_gzip_item_include mime ^text/.*
    mod_gzip_item_include mime ^httpd/unix-directory$
    mod_gzip_item_include handler ^cgi-script$
    mod_gzip_item_include handler ^server-status$
    mod_gzip_item_include handler ^server-info$
    mod_gzip_item_include handler ^application/x-httpd-php
    mod_gzip_item_exclude mime ^image/.*

    # Enable expirations
    ExpiresActive On
    # Default directive
    ExpiresDefault “access plus 1 month”
    # My favicon
    ExpiresByType image/x-icon “access plus 1 year”
    # Images
    ExpiresByType image/gif “access plus 1 month”
    ExpiresByType image/png “access plus 1 month”
    ExpiresByType image/jpg “access plus 1 month”
    ExpiresByType image/jpeg “access plus 1 month”
    # CSS
    ExpiresByType text/css “access 1 month”
    # Javascript
    ExpiresByType application/javascript “access plus 1 year”

    Header unset Pragma
    FileETag None
    Header unset ETag

    # cache images/pdf docs for 10 days

    Header set Cache-Control “max-age=864000, public, must-revalidate”
    Header unset Last-Modified

    # cache html/htm/xml/txt diles for 2 days

    Header set Cache-Control “max-age=7200, must-revalidate”

    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ – [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]

    suPHP_ConfigPath /php.ini

    order allow,deny
    deny from all

    ## EXPIRES CACHING ##

    ExpiresActive On
    ExpiresByType image/jpg “access plus 1 year”
    ExpiresByType image/jpeg “access plus 1 year”
    ExpiresByType image/gif “access plus 1 year”
    ExpiresByType image/png “access plus 1 year”
    ExpiresByType text/css “access plus 1 month”
    ExpiresByType application/pdf “access plus 1 month”
    ExpiresByType text/x-javascript “access plus 1 month”
    ExpiresByType application/x-shockwave-flash “access plus 1 month”
    ExpiresByType image/x-icon “access plus 1 year”
    ExpiresDefault “access plus 2 days”

    ## EXPIRES CACHING ##

    # Google Analytics Integration – Added by cPanel.

    AddOutputFilterByType SUBSTITUTE text/html
    Substitute “s|()?||i”

    # END Google Analytics Integration

    ## X-UA-Compatible: IE=8
    Header set X-UA-Compatible “IE=EmulateIE8″

    # BEGIN Expire headers

    ExpiresActive On
    ExpiresDefault “access plus 1 seconds”
    ExpiresByType image/x-icon “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”
    ExpiresByType application/x-shockwave-flash “access plus 2592000 seconds”
    ExpiresByType text/css “access plus 604800 seconds”
    ExpiresByType text/javascript “access plus 216000 seconds”
    ExpiresByType application/javascript “access plus 216000 seconds”
    ExpiresByType application/x-javascript “access plus 216000 seconds”
    ExpiresByType text/html “access plus 600 seconds”
    ExpiresByType application/xhtml+xml “access plus 600 seconds”

    # END Expire headers

    # BEGIN Cache-Control Headers

    Header set Cache-Control “max-age=2592000, public”

    Header set Cache-Control “max-age=604800, public”

    Header set Cache-Control “max-age=216000, private”

    Header set Cache-Control “max-age=600, private, must-revalidate”

    # END Cache-Control Headers

    # BEGIN Compress text files

    SetOutputFilter DEFLATE

    # END Compress text files

  3. Dude. you rule. This totally worked. Through a 500 at first but then cleared cache and it worked like a charm.. Thanks!!!!

  4. Wonderful!! Not sure how much but definitely faster right after I made the change. Thank you

  5. I’m running CE 1.7 I too had to comment out
    “php_flag zlib.output_compression on” because of 500 server error, that being said, great improvement!

  6. i have tried everything to make it work , however its giving me 500 error , if enabled the last line

    I dont have php.ini file on my server , so no way to change that

    Any help would be greatly appreciated

  7. What I found out trying this code was that I had some bad requests in the HTML HEAD (head.phtml).. I had placed some css and js links in there and Magento didn’t like it. I’d already linked to the same files in the local.xml so the site was working but very slowly. Tested the site at pingdom.com.. saw all the warnings against the rogue js and css links.. removed the links from head.phtml and the site was instantly transformed. I also noticed that the scriptaculous js files were taking some time to load.. I’m using jquery for sliders etc so not sure I need them. Does anyone know if you can remove the scriptaculous files or do they do something elsewhere?

  8. Its the best method to speed up the magento. For those this method doesn’t work, try enabling zlib compression in php.ini

    Set “zlib.output_compression = on” in php.ini

  9. awesome……………it works but depend on your server…
    i have tried on 2 server…old server & latest tech
    server… only working on latest tech server … cheerss… :D

  10. Kate, yes, you just need to uncomment (remove the # before the line) of the lines in the .htaccess of your file.

    It seems for me also that it’s faster also !

  11. I copied the above code and pasted it into my htaccess but I don’t see any difference in speed and Google is still asking for compression to be turned on. Any help would be fantastic – thanks!

  12. I’m sort of confused about what code I am replacing or adding? Do I find the lines of code you marked # and replace them with the lines of code beneath each line marked #? Sorry! And thank you!

  13. Thank you so much for this post.
    I have applies it on ver 1.3.2.4 and it works like charm.
    Is there more tricks to speed it further? :)
    I just like Formula 1

  14. Major props to you bro. this was an excellent solution. we have 50+ sites and they were all running super super slow, now they’re lighting fast!! thanks again

  15. Server error 500 solved.

    I had as well this error and found that I needed to enable mod_headers. On Ubuntu a2enmod headers
    Hope this helps somebody.

  16. this is throwing the same 500 server error for me as well. I removed the last line starting with “php” and the site is back up but not sure if speed is up or down.

    Any one have any suggestions? My magento version is 1.5.1.0

  17. I need to make my magento site faster. There fore I applied your setting in htaccess but

    # enable resulting html compression
    php_flag zlib.output_compression on

    particular code giving 500 error. Once removing the code the site runs but not faster.

    How can I add this compression code and if I need to set anything in server, then how can I do that one. Please guide as your help will be entirely grateful for me.

  18. Incredible !! Has solved my problem. On a clean mgto instalation admin panel go so so very very slow, and some times don’t answer.

    I have folow this sugestion, and now, is excelet fast.

    Thanks very very much for an excelent solution. ;)

    Regards,

  19. TinyBrick’s LightSpeed module has some pretty impressive results when it comes to speeding up Magento. The price might be a little steep, but the performance increases I’ve seen are totally worth it.

    You can see it here: [a href="http://zfer.us/4rilY"]TinyBrick’s Magento LightSpeed Module[/a]

  20. I’ve seen a similar saving with my magento website. Thanks so much for sharing! This is a MUST if you run on a shared hosting package!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <blockquote cite=""> <code> <del datetime=""> <em> <strike> <strong>. You may use following syntax for source code: <pre><code>$current = "Inchoo";</code></pre>.