Optimize Magento 2 Performance

optimization magento 2

For Magento 2 stores, Magento 2 Performance Optimizing is one of the important factors to lead your work more successful. In this guide we will help you make your store fast and snappy to use.

Steps to Optimize Magento 2 Performance

1. Make Sure Magento Runs in Production Mode

You’ve heard this before but… Make sure Magento is in Production mode. You’ll be surprised how often people forget to switch modes after fixing something in Developer mode or after a new install.

When you install Magento for the first time it will run in Default mode. This mode is best used to configure and test your Magento store before you open it to customers.

Default mode lets you tinker with a few cool features but doesn’t offer the best performance.

Besides Default, there are two other Magento modes:

Developer mode – used for verbose logging, bug hunting, and more in-depth configuration of your Magento install.
Production mode – this mode is optimized for performance. It’s the one you want to use day-to-day since Production mode will get you the best user experience.

Default and Developer modes are slow. Make sure you switch to production before you open for business:

php bin/magento deploy:mode:set production

2. Switch to Flat Catalogs

A classic Magento product structure will store product attributes across multiple DB tables. This means that when a user wants to see a single product, Magento will have to look up each product attribute in a different table. The more fragmented is this data, the more time it will take to complete each request.

Flat catalogs lead to fewer database queries per action since they will consolidate data and keep it together.

Flattening your category and product catalogs can help you speed up Magento 2.

When will you notice it most? The more products you have, the faster Magento will work with flat catalogs.

Go to

Stores > Configuration > Catalog.

Change both Use Flat Catalog Category and Use Flat Catalog Product to Yes.


3. Merge CSS and JS Files

The next step you need to follow is merging and minifying CSS and Javascript files, that means making the web page as light as possible for the fast loading. Please put Magento 2 into production mode.

./bin/magento deploy:mode:set production

Javascript File

  • Go to backend, Stores -> Configuration > Advanced > Developer > JavaScript Settings
  • Set Merge JavaScript Files to Yes
  • Set Minify JavaScript Files to Yes

4. Content Delivery Network 

Content Delivery Network (CDN) is a special system that can connect all cache servers. In addition to supported geographical proximity, CDN will take over the delivering web content and fasten the page loading.

Please follow this guide to set up CDN for Magento 2 stores. Go to backend, Stores -> Configuration > General > Web > Base URLs (Secure)


5. Enable caching

System > Cache Management.


6. Image Optimization

– Upload files that don’t exceed image requirements for a specific field. No need to use a 500×500 photo where a 200×200 will do. Even though Magento 2 will resize images automatically when you save a product, preparing your images is a good idea.

– Minify large images before upload. TinyJPGKraken.io, and other services are your best friends here. You can also download your existing images, tinify them and upload to the store.

– Cloudflare CDN will help you a lot.

A fast website is a small website. Check out how your store is doing in Magento image optimization. Can you beat our score?


7. Enable Compression

Follow the resources to enable compression by Google’s offer.

Let’s change nginx compression directives from:

  • gzip_types: text/plain application/x-javascript text/javascript text/xml text/css image/x-icon image/bmp image/png image/gif; to
  • gzip_types: *

8. Turn on Varnish Cache Tool

make sure your hosting provider supports Varnish. After you do that, go to

Stores > Configuration > Advanced > System > Full Page Cache, tranfer Caching Application to Varish Cache.


Tick off “Use system value” and turn on Varnish. You can leave Varnish configuration options as they are.

And with this fix done we are finished with the Developer mode. Use the command to return to Production:

php bin/magento deploy:mode:set production

For any questions or queries regarding Magento optimization, use the comments section below.