Magento Tutorials

Magento optimization technique for image, sql, cache – Step by step


As any other eCommerce platforms, Magento faces problems with speed and performance over time. Dealing with these issues and optimizing the system are the most important activities to SEO, sales and customers’ retention.

These below tips are some easy ways to keep your Magento website optimized:

1. Stay up-to-date

Magento always inform users if there is any new updates available so make sure you do not miss the update notification. New updates are usually released with performance improvements and bugs fixes.

magento optimization techniques

Below are the steps you need to keep in mind when upgrading into a new Magento version:

  1. Install a brand new version of Magento file tree
  2. Upgrade outdated database
  3. Don’t forget to merge old themes and extensions to the new version

2. Managing Cache

There are many ways to manage cache, such as browser caching, gzip compression, expire headers, and page caching.

In Magento, navigate to System/Cache Management to manage your caches (make sure that you enable all cache types)

magento optimization service

Browser Caching

Browser caching is one of many cache form that can be optimized. The following Gzip compression and expire headers are one of many code snippets that you can use for your .htaccess file (or .htaccess.sample for Magento 2).

Gzip Compression

Web pages and stylesheets are sent to browser as a gzip compression at server level.

<IfModule mod_deflate.c>
# Compress HTML, CSS, JavaScript, Text, XML and fonts
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/
AddOutputFilterByType DEFLATE application/x-font
AddOutputFilterByType DEFLATE application/x-font-opentype
AddOutputFilterByType DEFLATE application/x-font-otf
AddOutputFilterByType DEFLATE application/x-font-truetype
AddOutputFilterByType DEFLATE application/x-font-ttf
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE font/opentype
AddOutputFilterByType DEFLATE font/otf
AddOutputFilterByType DEFLATE font/ttf
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE image/x-icon
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/xml

# Remove browser bugs (only needed for really old browsers)
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
Header append Vary User-Agent

Expire Headers

Request a file from server or taking an available one from the cache browser are the function of expire headers.

<ifModule mod_expires.c>
ExpiresActive On
## Add default Expires header
<FilesMatch “\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$”>
ExpiresDefault “access plus 1 year”

Page Caching

The most powerful way for Magento optimization could be considered as page caching. Loading pages by visited one from cache makes the web server much faster.

You can check out some of Page Caching extensions for Magento below:

3. Image Optimization

Over 50 percent of a website’s pages is taken by images. Thus, optimizing image weight would potentially speed up your pages. There are a couple of online tools and extensions for Magento that you can use to compress and decrease your image weight:

magento image optimization

4. Merge CSS and JavaScript Files

Merging your CSS with JavaScript files helps decrease the number of HTTP requests to server and consequently reduce loading time on pages.

  1. Navigate to System/ Configuration/ Advanced/ Developers
    magento optimization tips
  2. In JavaScript Settings and CSS Settings, set the status to Yes and click on Save Config.
    magento optimization extension
  3. After files get merged, cache needs to be cleared and refreshed. (you can follow the mentioned cache process).

5. Clean Up Magento Database & Logs

As by Magento default, logs are kept for 180 days. Shorten this period can help you save some database space.

  1. Navigate System/ Configuration/ Advanced/ Advanced/ Log
  2. Change Save Log, Days to whatever you prefermagento optimization steps
  3. Click on Save Config

6. Run Magento Compilation (for Magento 1)

Everytime a page loads, lots of filesystem reads are generated. Magento compiler helps to decline these reads up to 50 percent.

  1. Navigate to System/ Tools/ Compilation
  2. Click on Run Compilation Process
    magento optimization mysql

Remember to disable Compiler before any new extension installation or Magento upgrade.

7. Indexes Update

Usually, Magento indexes are automatically updated to speed up MySQL queries. However, some updates need to be handled manually and make sure that you do not forget it.

  1. Navigate to System/ Index Management
  2. Select the indexes that you would like to update. In the dropdown, choose Reindex Date (Magento 1)
    magento index management or Update on Save (Magento 2)
    magento 2 index management
  3. Click Submit.


See more:
Magento 2 System Requirements
Magento 2 File Permissions



A knowledge craver who always strive to be wiser everyday.

    1 Comment threads
    0 Thread replies
    Most reacted comment
    Hottest comment thread
    1 Comment authors
    Mausin Shaikh Recent comment authors
    newest oldest most voted
    Notify of
    Mausin Shaikh

    Great article indeed. I think clearing cache is one of the most important things in Magento Optimization as it contains lots of products and files which affect the loading time. Images are a major part of any Magento website so doing proper image optimization is also very important. One should try to reduce the image size with extensions or upload the images which are optimized from an online source like Thanks for the great article Dom.