Saturday, 8 June 2013

Speed up magento site performance

Optimizing Magento Site Performance

This is a guide for optimizing Magento performance. Most optimizations can be performed on any version of Magento. Those intended for specific versions and newer will be indicated.

The default .htaccess file that comes with Magento has several sections dealing with performance. These configurations are commented out and will need to be turned on to realize their benefit.

Please backup the .htaccess file and do the given changes.

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:
 
<IfModule mod_deflate.c>

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

</IfModule>

Enable Expires Headers

  • NOTE: This does not work on Litespeed servers.
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:

<IfModule mod_expires.c>

############################################
## Add default Expires header
## http://developer.yahoo.com/performance/rules.html#expires

    ExpiresActive On
    ExpiresDefault "access plus 1 year"

</IfModule>

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

Magento Admin Tweaks

There are a couple of features that can be enabled in the back end of Magento to optimize performance. Generally, these features are available on versions 1.4.0.1 and higher and should be performed when most of the development work is done.

Combine CSS and JS Files

This feature reduces the number of HTTP requests. For versions earlier than 1.4.x, the Fooman_Speedster extension can be used instead.
  1. In the Magento Admin, go to System > Configuration > Developer.
  2. Under "Javascript Settings", change "Merge Javascript Files" to YES.
  3. Under "CSS Settings", change "Merge CSS Files" to YES.
  4. Clear the cache.

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. Stores with over 1000 products should enable Flat Catalog for Products.
  1. In the Magento Admin, go to System > Configuration > Catalog.
  2. Under "Frontend", change "Use Flat Catalog Category" to YES.
  3. Under "Frontend", change "Use Flat Catalog Product" to YES. (optional)
  4. Clear the cache.

Enable the Magento Compiler

Magento's application files are searched for in the following order:
  • app/code/local
  • app/code/community
  • app/code/core
  • lib
This search is performed for every page load, every time, resulting in a lot of filesystem reads. The Mage_Compiler reduces the number of reads by copying all of the application files to a single include directory. It also caches the most frequently used pages.
  1. In the Magento Admin, go to System > Tools > Compilation.
  2. Click "Run Compilation Process"

Other Performance Tweaks

Parallelize Downloads

Most browsers limit the number of concurrent connections to a domain to four. If your page has a lot of components coming from the same domain, this can result in a longer page load time. You can trick the browser into grabbing more components by using different subdomains for static components. This is as simple as creating pointer domains in Siteworx. However, due to the way that Nexcess configures the subdomain logic in the Vhost file, an additional modification is necessary to make this work on our servers.
  1. Create Pointer domains in Siteworx.
    • This can be a single "static.example.com", or separate "js.example.com", "media.example.com", and "skin.example.com" domains.
  2. Once they are resolving, change the media, js, and skin URLs in Magento as follows:
  3. Edit the Vhost file so that apache doesn't try to load the sub-directories ../media, ../skin, or ../js, but rather the web root itself. Directly below the following lines:
    NOTE: If you are on a Managed or Shared server, please open a ticket with support@nexcess.net for assistance with this.
      # subdomain logic
      RewriteEngine On
      RewriteOptions inherit
      RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
      RewriteCond %{HTTP_HOST} !^example\.com [NC]
    
    Add:
    
      RewriteCond %{HTTP_HOST} !^js\.example\.com [NC]
      RewriteCond %{HTTP_HOST} !^media\.example\.com [NC]
      RewriteCond %{HTTP_HOST} !^skin\.example\.com [NC]
  4. Save the file and restart Apache.
  5. Clear the cache and reload the page to make sure the static content is coming from the new URLs.


    Other Way to Speed Up Magento Site Performance

    Speed up Magento with these simple admin settings

    Please Follow the below general Steup to Speed up your magento Store

    1. Enable cache

    Most users are well aware of this one ;) .
    Just navigate to System > Cache Management and enable all cache types.
    Magento Cache Management
    Magento Cache Management

    2. Re-index data

    Regularly indexing Magento data will also have some impact on performance.
    Under System > Index Management select all indexes and hit the “Reindex Data” submit button.
    Magento Index Management
    Magento Index Management

    3. Enable JavaScript file merging

    Combining all JavaScript files into one will greatly reduce the number of HTTP requests your Magento site makes to the server and will have a nice impact on speed.
    Navigate to System > Configuration > Developer > JavaScript Settings and select “Yes” under “Merge JavaScript Files”.
    Combine All JavaScript Files
    Combine All JavaScript Files

    4. Combine CSS files

    Like with JavaScript files, combining all CSS files into one will reduce load time and increase speed. Magento also has an admin setting for that but we don’t recommend turning it – it is much better to use Ultimento’s Magento themes which are truly optimized for speed. In Ultimento there is only 1 combined CSS file that is also compressed and minified.
    If you’re not running Ultimento, you can combine all CSS files into one via the Magento admin:
    Go to System > Configuration > Developer > CSS settings and select “Yes” for “Merge CSS Files”.
    Combine All CSS Files
    Combine All CSS Files

    5. Turn off the logs

    On a production Magento installation make sure all logs are turned off!
    The settings are under System > Configuration > Developer > Log Settings.
    Magento Log
    Magento Log

    6. Enable the compilation

    Magento’s compilation is a great tool to speed up a production installation.
    Go to System > Tools > Compilation and hit “Run Compilation Process”.
    Magento Compilation
    Magento Compilation

    Of course there’s many other things besides these admin settings you can do to speed up your Magento store!

1 comment:

  1. Nice blog. Got some ideas in my developing career.
    Also got some more tips to optimize the Magento store... Read More

    ReplyDelete