How to Optimize Magento ?

1. Enable Flat Catalog

Magento uses the EAV model (entity attribute value) to store customer and product data. Enabling the flat catalog for categories and products merges product data into one table, thereby improving performance by responding to MySQL queries faster. If your eCommerce store has more than 1000 products, this can very beneficial.

2. Image Optimization

As we mentioned in a previous post on lossless image compression, on average 56 percent of a website’s page weight is made up of images. Optimizing your product images can dramatically increase the speed of your pages as this decreases their download times. You can compress them before uploading them using a tool like PhotoShop or there are a number of extensions you can use to auto-optimize them. For Magento version <2 users, the following extensions are available.

3. Concatenate (merge) CSS and Javascript Files

Magento version <2 actually has a built in feature to concatenate (merge) your CSS and Javascript files into one file. This will reduce your total number of HTTP requests and in turn help speed up the loading of your pages.

  1. Navigate to “System” → “Advanced” → “Developer.”
  2. Under “JavaScript Settings” and “CSS Settings” change the dropdown to “Yes” and click on “Save Config.

4. Enable Magento Compilation

Magento has a compilation feature which has been reported to sometimes give up to a 50% performance boost. By default, Magento’s application files are searched in a certain order everytime the page loads, which results in a lot of filesystem reads. The Magento compiler reduces these reads by copying all of these files into a single include directory and also caches ones that are used more frequently.

  1. Navigate to “System” → “Tools” → “Compilation.”
  2. Click on “Run Compilation Process.”

5. Clean Up Magento Database & Logs

By default, Magento keeps logs up to 180 days. This can result in your database growing quite large. You change it to something smaller like two weeks (14 days) to save space.

  1. Navigate to “Stores” → “Configuration” → “Advanced”→ “System” → “Log.”
  2. Under “Save Log, Days” change it to 14 days, or whatever you prefer.
  3. Click on “Save Config.”

You can also manually clean up your database by emptying the log tables.

  1. In phpMyAdmin select all of the log_% tables and select “Empty” from the drop-down box.
  2. Click on “Yes” when it asks you if you really want to TRUNCATE the tables.

6 . Server Level Config and .htaccess Tweaks

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.

7 . Caching

ENABLING MEMCACHED FOR MAGENTO 1.9 AND OLDER VERSIONS

To enable memcached for Magento 1.9 and older versions, you need to add some settings to the local.xml file. To do this, follow these steps:

  1. Using your preferred text editor, navigate to the directory where you installed Magento, and then open the app/etc/local.xml file.
  2. Add the following lines just before the closing </global> tag:
    <cache>
        <backend>memcached</backend>
        <memcached>
            <servers>
                <server>
                    <host><![CDATA[127.0.0.1]]></host>
                    <port><![CDATA[11211]]></port>
                    <persistent><![CDATA[1]]></persistent>
                </server>
            </servers>
            <compression><![CDATA[0]]></compression>
            <cache_dir><![CDATA[]]></cache_dir>
            <hashed_directory_level><![CDATA[]]></hashed_directory_level>
            <hashed_directory_umask><![CDATA[]]></hashed_directory_umask>
            <file_name_prefix><![CDATA[]]></file_name_prefix>
        </memcached>
    </cache>

    If these lines are not contained in the <global> section, Magento will not use memcached.

  3. Save your changes to the local.xml file. Memcached is now enabled.