How to optimize Magento performance

    October 16, 2019

    This guide demonstrates how to optimize performance for Magento 1 and 2, though some methods only work for Magento 1. 

     Read Four Ways We Make Your Magento Store Faster.

    Magento 1 and 2: Tweak .htaccess

    The default .htaccess file included with Magento includes several sections discussing performance. Comment out the following sections and enable them to apply their benefits.

    Disable ETags

    ETages allow browsers to validate cached page components from visit to visit. While useful, they can hamper websites hosted on server clusters in some cases. Disabling them as follows will often improve performance: 

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

    Enable Expires headers

    Attention: The following will not function on LiteSpeed servers.

    Browsers use Expires headers to define the lifespan of cached page components. While all page components should include Expires headers, static components and images should use far-future Expires headers. 

    To activate this feature, uncomment the appropriate line and, directly above it, add ExpiresActive On. For example:

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

    Enable output compression

    This section discusses how to compress both static content such as text, CSS, JavaScript, and individual HTML files, and dynamic content such as content generated by CMSs like Magento, WordPress, and ExpressionEngine, among others.

    Static content

    This will activate the Apache mod_deflate module and compress static resources into smaller files before transfer to the browser. To enable, uncomment the appropriate lines as shown below:

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

    Dynamic content

    If, however, your site relies on dynamically generated content, instead create a file called .user.ini in your site's document root folder with the following contents:

    zlib.output_compression = on

    If you are a Nexcess client, we can make this the default setting for your account upon request. 

    Magento 1 only: Administrative tweaks

    These features are generally available on versions 1.4.0.1 and later. However, we recommend applying them only after concluding the majority of your developmental tasks.

    Combine CSS and JS files

    This feature reduces the number of HTTP requests. For versions earlier than 1.4.x, use the Fooman_Speedster extension instead.

    ATTENTION: Combining CSS/JS when using a CDN will break CSS/JS until the CDN updates. Therefore, we recommend starting this process during early non-peak hours.

    1. In the Magento Admin, select System > Configuration > Developer.

    2. Under Javascript Settings, from the Merge Javascript Files drop-down list, click YES.

    3. Under CSS Settings, from the Merge CSS Files drop-down list, click YES.

    4. Clear the cache.

    Enable flat catalog

    Magento uses the EAV model to store customer and product data. This upgrades extensibility at the cost of prolonging SQL queries. 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. From the Magento administrator interface, go to System > Configuration > Catalog.
    2. Under Frontend, from the Use Flat Catalog Category drop-down list, click YES.
    3. If desired, under Frontend, change Use Flat Catalog Product to YES.
    4. Clear the cache.

    Magento 1 only: Other performance tweaks

    Configure the Nexcess CDN

    For details, refer to How to configure CDN access for Magento

    Clean the database

    Magento's database can quickly become sluggish due to un-maintained log tables. Refer to How to perform Magento database maintenance for more information.

    For 24-hour assistance any day of the year, contact our support team by email or through your Client Portal.

    Was this article helpful?

    Send feedback

    Can’t find what you’re looking for?

    Our award-winning customer care team is here for you.

    Contact Support