Processing... Please wait...

Product was successfully added to your shopping cart.

Speed Up Magento in 23 Field Proven Steps (M2 tips included)

Do you want to speed up Magento performance? Of course you do! And you are not alone.

The one of the most popular eCommerce platform might be slow. The main reason for its poor performance is an excessive use of various customizations.

Here are 23 field proven steps that will help you increase Magento 1 and Magento 2 web page speed:


23 Ways to Speed Up Magento:


  1. Optimize TTFB
  2. Minimize latency
  3. Optimize Server configuration
  4. Choose fast hosting
  5. Optimize VPS for Magento
  6. Audit Magento code
  7. Optimize Start Render time
  8. GZIP compression
  9. Domain sharding
  10. Utilize the power of HTTP/2
  11. Leverage browser caching
  12. Prioritize above-the-fold content
  13. Remove render-blocking CSS and Javascript
  14. Reduce the size of visible content
  15. Put above-the-fold content first
  16. Optimize document complete time
  17. Serve optimized images
  18. Sign up for CDN
  19. Optimize fully loaded time
  20. Don't abuse jquery.ready
  21. The less third-party JS the better
  22. Never use JS bundling (Magento 2 specific)
  23. Run store in production mode (Magento 2 specific)



There are ways to make your Magento site fly and I will show you how to do that in a sec. But first let us define what we will use to measure site speed.



How to Measure Magento Speed


When a browser loads a web page it does certain actions:

  • It receives html data from a server.
  • It analyzes data and loads external files you might have on the page (CSS/JS/images/fonts etc).
  • It then builds what's called a DOM (Document Object Map).
  • It renders the page (puts elements on the screen).

We can define 3 time periods that measure how quickly a webpage loads:

  • Time to first byte (TTFB) or server response time: the time from when a user clicked on a link or typed in a site URL until the first bit of information from the server arrived.
  • Start render time: the first point in time that something was displayed to the screen. Before this a user was looking at a blank page.
  • DOM complete or document complete time: the point in time when the browser considered the page loaded (onLoad javascript event fired). All the content has been loaded except content that is triggered by javascript execution.
  • Fully loaded time: a webpage is loaded and no network activity is performed by a web browser.

Definitions are taken from webpagetest.org.

TTFB < Start render < DOM complete < Fully loaded

The waterfall chart The Waterfall Chart

The most important time in my opinion is the start render time. The quicker you show a user that something is happening after he requests a webpage the faster he thinks the site is.

There are 3 main time limits that describe user perception of how quick a web application is [study]:

  • 0.1 second response time – a user feels that a system is reacting instantaneously.
  • 1.0 second response time – a user notices the delay, but it doesn't bother him
  • 10 second response time – the limit for keeping the user's attention focused. For longer delays, a user will want to perform other tasks while waiting for the computer to finish.

We want to keep start render time around 1s to make a user feel a web site is fast.


1. Optimize Time to First Byte


Server response time or time to first byte (TTFB) consists of the time a browser's request goes to the server and server response goes back to a browser (latency) and the time a server generates HTML.

Google recommends having TTFB around 200ms. 1s TTFB is considered bad.

To lower TTFB you need to work on latency, server configuration and Magento codebase. Here are my in-depth tutorials on how to optimize TTFB for Magento 1 and Magento 2.


2. Minimize Latency


Host your website as closer to your main audience as possible. If you sell shoes in London, do not sign up for hosting in Japan. Common sense.

Do not think that SSL will impact your TTFB much. SSL negotiation time is negligible but the SEO benefit is obvious.


3. Optimize Server Configuration


Optimizing server configuration includes choosing the right hosting and setting up server software. If you run a Magento 2 you might want to check out the hardware requirements for a decent performance.


4. Choose Fast Hosting


A Magento site can't run on $5/mo shared hosting. If you want good TTFB and start render times, sign up for VPS or Magento-optimized hosting – Nexcess, Magemojo and others. Do a Google search and see what others recommend.


5. Optimizing VPS for Magento


If you plan on running VPS or a dedicated server, you need to optimize server software and MySQL database.

Options to choose your server setup are endless and depend on your expertise. You can configure NGINX, Apache, Varnish, HHVM, php-fpm, Redis, memcache.

I will list possible solutions for high magento performance:

  1. Varnish + NGINX + PHP-FPM + Redis
  2. Varnish + NGINX + HHVM + Redis
  3. Use PHP7 with Magento 2 or PHP7 + Inchoo patch with Magento 1.x
  4. Host webserver and database on different servers
  5. Use MySQL master-slave replication for separate reads and writes


5.1 Server Performance Hogs


I will list common server misconfigurations that slow Magento sites:

  • Disabled MySQL query cache. Modern MySQL servers come with query cache disabled by default. Enable it – it will speed up Magento significantly.
  • Slow disk I/O. Make sure your host provides you with SSD (solid state disk) storage.
  • RAM shortage. When the system runs out of RAM, it puts data on disk (swap), making things slow.


6. Audit Magento Code


Your Magento site php code and template files are the main reason for poor server response time.

First, you need to profile the code and identify parts that slow site down. Magento comes with a built-in profiler you can use. You can use third-party extension Aoe Profiler or sign up for NewRelic application performance management tool.


6.1 Magento Code Performance Hogs


  • Observers that run on every page request
  • Poorly written template files
  • A slow MySQL query(s) somewhere

Here is a detailed tutorial I wrote on how to optimize TTFB with Magento profiler.


6.2 Poorly-written Magento Code


An example of bad Magento code that I encounter too often:

Loading Magento models inside a loop. That happens in product list templates; people iterate over product collection and load the product model every time:

foreach($collection as $product){
  $product = Mage::getModel('catalog/product')->load($product->getId());

Don't do that. Better construct your collection to have all the data you need. Magento model loads are expensive.


7. Optimize Start Render Time


Start render time (SRT) is the first point in time when a user sees the content after requesting the webpage. It could be a background image or some text blocks, but from that time on he knows something is happening. Start render time in my opinion is one of the main factors by which a user judges how fast the site is.

According to the 3 main time limits [study] I mentioned earlier, we need to keep the start render time to around 1s.

SRT consists of:

  • Time to first byte (TTFB)
  • Time it takes to download a page HTML
  • <head> section parsing and downloading resources (JS/CSS external files) a browser finds there
  • Initial layout calculation

After we understand what start render time is, we have options to optimize it.


8. GZIP Compression to Shrink Page Size


Compress your html page so that a browser has fewer kilobytes to download. Enable gzip compression on the server side – see instructions for your web server. Confirm you have gzip enabled by this online testing tool.


8.1 NGINX GZIP Compression


NGINX example configuration to enable gzip:

http {
        gzip on; 
        gzip_disable "msie6";

        gzip_vary on; 
        gzip_proxied any;
        gzip_comp_level 6;
        gzip_buffers 16 8k; 
        gzip_http_version 1.1;
        gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript;

You need to restart NGINX for the changes to take effect.


8.2 Apache GZIP Compression


When running Apache you can enable gzip by changing .htaccess file inside your Magento root folder:

<IfModule mod_deflate.c>
  AddOutputFilterByType DEFLATE application/javascript
  AddOutputFilterByType DEFLATE application/rss+xml
  AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
  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
  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


9. Domain Sharding


Domain sharding is splitting external resource files (JS/CSS/images etc) across multiple domains. Why bother? Because a browser can download files in parallel but has a limit per domain. For example Chrome can do 6 concurrent connections.

If we can split images, js, css files across multiple subdomains, we can make a browser download resources a lot faster.

UPDATE: domain sharding is not needed when you use HTTP/2. And the use of HTTP/2 is recommended.


9.1 Domain Sharding in Magento


Magento supports domain sharding by default and it is easy to setup:

1. First create subdomains:

  • skin.domain.com
  • media.domain.com
  • js.domain.com

and point them all to the same IP and file folder your main domain is pointing to.

2. Go to Magento backend main menu System > Configuration > Web and set Base Skin URL, Base Media URL and Base Javascript URL for unsecure and secure (if you have one) links.

3. Flush cache and confirm your resources are now served from subdomains.


10. Utilize the power of HTTP/2


HTTP/2 is the new generation of Hypertext transfer protocol. It has many performance improvements that allow a browser to load a webpage faster and be less resource-intensive.

Here are the key differences to HTTP/1.x:

  • HTTP2 is binary, instead of textual
  • It is fully multiplexed ( can send multiple requests over the same connection ).
  • It can use one connection for parallelism ( meaning it can load resources ways faster ).
  • It uses header compression to reduce overhead.
  • It allows servers to "push" responses proactively into clients browser's caches.


All major web servers (Apache, Nginx, IIS) support HTTP2 out of the box. Here are the examples of configuration:



10.1 Enable HTTP/2 for Apache


Apache can use the latest HTTP protocol from version 2.4.17 up.

First install mod_http2 module.

Next enable it:

LoadModule http2_module modules/mod_http2.so

And modify Protocol directive:

Protocols h2 h2c http/1.1



10.2 Enable HTTP/2 for Nginx


You will need Nginx 1.9.5 up. All you will have to do is to add http2 parameter in listen directive.

server {
                 listen 443 https;



You can use Google Chrome Developer Tools to verify the correct installation (of course if you are using chrome browser). Open it up, go to Network tab and check for Protocol column - it should say h2. (To view Protocol column right click on any column and select it):

HTTP/2 Verification HTTP/2 Verification

11. Leverage Browser Caching


A browser can cache files for faster access. You can take advantage of this to lower the start render time.

Configuration depends on your server:


11.1 Leverage Browser Caching for NGINX


Add this inside server directive:

        location ~* \.(js|css|png|jpg|jpeg|ico|gif|pdf)$ {
              expires 300d;
              add_header Pragma public;
              add_header Cache-Control "public";


11.2 Leverage Browser Caching for Apache


Add this into your .htaccess file:

<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType text/css "access plus 1 month"
ExpiresByType application/pdf "access plus 1 month"
ExpiresByType text/x-javascript "access plus 1 month"
ExpiresByType application/x-shockwave-flash "access plus 1 month"
ExpiresByType image/x-icon "access plus 1 year"
ExpiresDefault "access plus 2 days"

as taken from Gtmetrix.


12. Prioritize Above-the-fold Content


Above-the-fold content is the part of a page that you see before you scroll down. It is also referred to as visible content.

Prioritize visible content – load and display it as quickly as possible.

How do I optimize above-the-fold content? Here are some tips:


13. Remove Render-blocking CSS and Javascript


The less time a browser spends parsing <head> section of your webpage the better. Ideally, only JS and CSS needed to display above-the-fold content should be put in between head tags.

Go through your css files and identify rules that are applicable to visible content. Inline those rules. Do the same for javascript.

Here is a detailed tutorial on how to optimize CSS delivery and an extension to defer Javascript parsing (remove render-block Javascript).


14. Reduce the Size of Visible Content


The less visible content a browser has to download the better. Make sure images are optimized. Remove any content that is not needed.


15. Put the Above-the-fold Content First


Analyze the page HTML and make sure visible content goes first.

Refer to this tutorial on how to prioritize visible content.


16. Optimize Document Complete Time


Besides start render time and first byte time improvements, there are a few things you can do to decrease document complete time:


17. Serve Optimized Images


UPDATE: for more details on how to optimize images refer to my other post.

The less time browser needs to download images the better.

There are various online tools that help you optimize images. Image Optimizer, Compressor.io, TinyPNG are just a few.

If you are familiar with linux command line, then you can bulk optimize jpegs, pngs with jpegtran and optipng. Jpegtran is part of libjpeg package.

Useful oneliners to bulk optimize images for Magento site:

find ./skin ./media ./js -type f -iname '*jpg' -exec sh -c 'jpegtran -outfile "{}.out" -optimize "{}"; mv "{}.out" "{}"' \;
find ./media ./skin -iname '*.png' -exec optipng -o5 -keep -preserve '{}' \;


18. Sign up for CDN


Content Delivery Network (CDN) is a web service to host your Magento site external resources: CSS/JS files, images, fonts etc. It aims to serve those files at lot faster than you can with your own server.

Magento supports CDN by default, no extensions needed. Go to System > Configuration > Web and set secure/unsecure URLs for media, skin, js resources.

There are many CDN providers to choose from: MaxCDN, KeyCDN, Amazon CloudFront and others.


19. Optimize Fully Loaded Time


If you have done start render, first byte and document complete times optimization, there is the final step – fully loaded time improvements.


20. Don't Abuse jquery(document).ready


Choose onLoad events carefully. Don't put CPU intensive tasks in jquery.ready – it slows down page loading.


21. The Less Third-party Javascript the Better


Examine what third-party javascript files you add to your Magento store. Do you really need them?

Well known JS code like Google Analytics, Facebook is all optimized and its performance impact is negligible. Others – use with caution and always test.

This tip is especially useful for mobile networks. You can check out other mobile optimization tweaks for M2 site in my previous post.



22. Never Use JS Bundling (Magento 2 specific)


Magento 2 can group JavaScript files to lower HTTP requests a browser needs to make to load a page. That is supposed to make a site faster.

Let me first say that it is useless with HTTP/2.

Second, it does more harm than good. The bundled JS file is huge in size (5-13Mb) which makes mobile speed suffer significantly (here is a bug report).

I advise to keep JS bundling off. Go to backend dashboard > Stores > Configuration > Advanced > Developer > Javascript Settings and set Enable Javascript Bundling to No:

Turn off JS Bundling Turn off JS Bundling

23. Run Store in Production Mode (Magento 2 specific)


M2 has three running modes: default, developer and production. Production mode is the fastest one.

Make sure you always put your store in production mode.

You will need to obtain SSH (Secure Shell) credentials to change running modes. The command to find out what's the current mode:

php bin/magento deploy:mode:show

To switch to production:

php bin/magento deploy:mode:set production



Bonus: Implement Magento Performance Tests


Include performance benchmarks into your workflow. Every time you add an extension from Magento, connect or roll out new feature – see what impact it has on site speed. Does it slow Magento? Debug or go for another module.

A few tools that help you speed up Magento and evaluate its performance (free to use):

1. webpagetest.org – provides you with page-loading waterfall charts and tons of other useful information. Supports mobile browsers.

2. Google Chrome Timeline – helps you analyze frontend performance. Takes a little time to get used to, but once you are familiar with it, it gives you valuable insights into why your Magento is slow.

3. Google PageSpeed Insights – an online tool that tells you what to do to boost site performance. Work on suggestions by Google and improve Magento speed.


Run a Magento 2 store? Check out 3 simple fixes to improve M2 performance.


Struggle with slow Magento! We can help! Fill out the form below to get a free quote.


Other articles you might be interested in:

  1. Magento 2 hardware requirements (4 working tips for decent performance)
  2. Magento TTFB optimization to reduce time to first byte
  3. Magento Performance Optimization - 7 steps to faster website
  4. HHVM: 4x magento performance boost!
  5. Magento 2 TTFB (Time To First Byte) Optimization


If you find this post interesting do not hesitate to sign up for our newsletter and join the 874 people who receive Magento news, tips and tricks regularly.

Thank You!


8 thoughts on “Speed Up Magento in 23 Field Proven Steps (M2 tips included)”
  • deep
    deep January 3, 2018 at 11:38 pm

    wow. awesome contents

  • Randy de Decker
    Randy de Decker November 11, 2017 at 4:28 am

    Good article that I've bookmarked. I've implemented a lot of these actions above, but good to know there are still some improvement points left.
    I agree with Steve that HHVM should not be used with M1. And a good FPC decreases load times substantially, but offcourse does not improve the uncached pages loadtime.

  • Fayyaz Khattak
    Fayyaz Khattak September 28, 2017 at 11:40 am

    Well, I have used Cloudways Magento Full Page Extension powered by Amasty to speed up the Magento performance. I avoided using heave theme and used trusted extensions to accomplish some tasks on my ecommerce store. The store now loads within 2 seconds, and I am delighted with the reviews of my customers about the performance of the store.

  • Alexander
    Alexander July 27, 2017 at 3:32 am

    Magento is an ecommerce heavy open source platform. It is a big problem for you when your magento store runs slowly and at that time you have to setup it properly.

  • Tej singh
    Tej singh May 30, 2017 at 4:35 am

    Tottaly agreed to all the above points foe increased magento page speed but one point we are forgetting is what happens if we clear cache in middle of the day when customers are actually hitting the site, best solution is to have cache warmer that quickly crawls and puts the page back under cache.

  • olivedev
    olivedev January 19, 2017 at 5:11 am

    Some great tips for optimizing Magento's speed. Few more things that you can do to tune the performance are: install Turpentine – Varnish Cache plugin and configure Memcached with Magento 2. You will notice a significant increase in speed.

  • Konstantin Gerasimov
    Konstantin Gerasimov October 25, 2016 at 3:41 am

    @Steve - thank you for your comment

    what did you mean by " I’d take care with infrastructure suggestions that are outside Magento’s requirements ( so no HHVM, > 5.4/5/6 on Magento 1.x and so on ). Don’t want to get sued!"?

    I run HHVM with magento 1.x with no problems

    master-slave setup for magento is a great way to speed things up - master for writes, slave for reads - magento supports separate reads/writes databases.

  • Steve Holdoway
    Steve Holdoway October 25, 2016 at 1:20 am

    Great to see a well thought out list rather than the usual regurgitated posts from a decade ago! However, I do disagree with a few of these, and have a few suggestions ( well, what do you expect from a grumpy old bugger like me! )...

    - If you split database and web server then you've not only added a new point of failure ( and potential performance problems ), but you now have to build up / tear down TCP connectivity to extract data from the database, rather than ( with a properly configured server ) just pick it out from local memory.

    - it's very unlikely that your site will ever become busy enough to require a master / slave database setup. Also remember that this will slow things down if you're not very careful indeed.

    - there are many more file types that can take advantage of browser caching.

    - domain sharding is pointless with use of a CDN... just hand the heavy lifting over to them and let them sort it out.


    - what about http2?

    - I'd take care with infrastructure suggestions that are outside Magento's requirements ( so no HHVM, > 5.4/5/6 on Magento 1.x and so on ). Don't want to get sued!

    - tuning of the OS?

    - and finally what about caching!