Skip to main content
Blog General

TIPS & TRICKS To Improve Magento Performance

Balasubramaniam
April 6, 2015 |

Get the high performance and scalability to your online store by choosing Magento 2 migration. Go live in 3 weeks. Get in Touch.

Magento performance has been considered an important parameter in improving the customer experience. With huge product lines and numerous extensions, performance of certain Magento stores has taken a hit. There are a few tricks that we have up our sleeve to improve the Magento performance.

This blog post focuses purely on the tweaks that we need to do in the .htaccess file to improve performance.

Step 1: Gzip Compression & Enable Output Compression:

Gzip compression is used to increase the site performance by compressing the server responses sent to the client. Enabling gzip compression in Magento is a simple process, we need to make a slight modification to the .htaccess file in the root directory. By default, Magento includes the required lines to enable gzip compression, but they are disabled. To enable, simply uncomment the appropriate lines

<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
  # 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 output compression by uncommenting the following line of code.

## enable resulting html compression
php_flag zlib.output_compression on
 Step 2: Leverage Browser Caching and Expires Headers

Browsers use “Expires Headers” to determine how long a page component can be cached. Expires headers checks whether a resource on a website needs to be requested from the source or if it can be fetched from the browser’s cache. For example, when we set an Expires header for all jpeg images, the browser will store those resources in its cache. The next time the visitor comes back to the page, it will load faster since the browser will already have all those images in its cache. To enable, change the below code

The existing code,

<IfModule mod_expires.c>
    ############################################
    ## Add default Expires header
    ## http://developer.yahoo.com/performance/rules.html#expires
    ExpiresDefault "access plus 1 year"
</IfModule>

 To,

<IfModule mod_expires.c>
    ############################################
    ## Add default Expires header
    ## http://developer.yahoo.com/performance/rules.html#expires
    ExpiresActive On
    ExpiresDefault "access plus 1 year"
    # My favicon
    ExpiresByType image/x-icon "access plus 1 year?
    # Images
    ExpiresByType image/gif "access plus 1 year"
    ExpiresByType image/png "access plus 1 year"
    ExpiresByType image/jpg "access plus 1 year"
    ExpiresByType image/jpeg "access plus 1 year"

    # CSS
    ExpiresByType text/css "access 1 year?

    # Javascript
    ExpiresByType application/javascript "access plus 1 year"
</IfModule>
Step 3: 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

Converting a normal visitor into a potential customer is purely based on the experience that a customer receives in an eCommerce portal. These simple tweaks in Magento will help a lot in enriching that experience.

Balasubramaniam

Balasubramaniam, aka Bala, is a Certified Magento Developer Plus Senior Software Engineer and one of our gems in the Magento team. A quick learner, he owns the projects that he works in and ensures they are delivered on time. He is very good at analyzing/fixing bugs and Magento customizations.

More posts by Balasubramaniam