Magento 2 Add to Cart Is Slow. How to Fix It?

Magento 2 Add to Cart Is Slow. How to Fix It?

Magento 2 Add to Cart Is Slow. How to Fix It?

Over the years the community managed to successfully combat the majority of Magento speed issues using a variety of tools (most of which boil down to cache management, profiling, and manual bottleneck fixes).

When it comes to speed issues, lots of developers are tempted to turn to caching to mitigate sudden performance drops. It’s a common misconception even among developers but cache almost never equals speed. It’s a great tool to deal with other Magento (both 1.9 and 2.x) inefficiencies such as cache swelling and file fetching, but cache doesn’t make your whole store faster.

magento add to cart slow

It’s only used to facilitate cached content delivery. And, of course, Magento doesn’t cache the Shopping Cart (for obvious reasons). Magento Add to Cart logic and Cart View itself both need to stay dynamic throughout the whole user experience.

Users need the ability to add or remove products from the cart at any time during shopping to apply promo codes, change delivery or payment options, or in any other way change your store content.

9 Tips How to Speed Up Magento Add to Cart

Both Magento 1.9 and Magento 2 Add to Cart can be slow. In part, this is because neither of them caches Cart contents or Add to Cart functionality. But even uncached content should still load in less than 1 second. In order to find out the real cause of the problem, you’ll need to manually examine two possible bottlenecks: hosting and code.

There are a number of reasons why something can go wrong: template inefficiencies, extension issues, nonoptimal server configuration, inadequate resource allocation, unnecessary overheads, etc. Without a good tool to analyze which call or function creates too much stress on the system, you won’t understand what you need to fix in the first place. To understand why Magento 1.9 and 2.x add to cart procedure is slow, read on.

1. Determine Which Part of the Store Creates the Bottleneck

In order to find the true bottleneck, you’ll need to test the performance of different parts of the store. Bear in mind that web hosting infrastructure will determine the baseline of your store speed. Hardware plays a key role in creating the foundation of what you can expect from the store.

How can you tell if your real store suffers from underpowered hardware? Install default Magento with sample data and measure how well it performs. If the sample store runs poorly, then this is your bottleneck. Right here.

If you suspect that sample data does not reflect the current load on your store, generate more categories and products using this guide. Create as many new products and categories as you need to come as close as possible to the real-life setup of your store.

config_generate-data magento speed up add to cart

Depending on your exact needs, there are two solutions you can implement:

  • upgrade to a better hosting plan (choose Magento optimized servers if you can),
  • fix your server configuration if the hardware is powerful enough already.

If you see that the demo Magento store runs well, then the issue is with the code.

Depending on the reason, we will need to fix the underlying issue. Start with profiling the Cart with the default Magento Profiler or run any profiler of your choice. Once you find the bottleneck, you’ll need to deal with it. Here’s a handy article to get you started with the Profiler. 

If you want to use something more capable, take a look at MGT Developer Toolbar. It’s a great alternative to the default tool and 100% worth a quick look.

Profiling works well if the bottleneck is in a specific database table, third-party extension, a few rogue scripts, or pieces of content. Working with the load table you can sort by time to see which items have the biggest values in the fields Time and Cnt.

If you see that the store works fine and the problem is inside one of the extensions, switch them off on test setup and then turn on one by one to find those that slow your Magento Cart the most. Profiling works best for this type of analysis where you can rule out one item at a time and then move on to the next.

Here we’ve listed a few tips on how to make the Cart lighter without sacrificing too much.

2. Speed Up Inventory Management

To understand why Magento Add to Cart button can be very slow you need to know what happens when the user clicks this button. Adding to Cart anything means Magento first has to check if the item is still available. This check is important to resolve possible conflicts when 2 or more users want to buy the same product with limited inventory.

The check happens within the Inventory Management section of the store where Magento looks up item availability from a specific database table and then changes its value according to the user’s actions in the store.

Okay, since now we understand the mechanism of the delay we can do something about it. Two solutions:

  • speed up the database to shorten inventory lookup time,
  • disable inventory management to boost Add to Cart performance (not a good idea unless your store sells thousands of identical items).

3. Disable the Carriers You Don’t Use

Fetching carrier rates takes time. With the exception of Flat Rate and Free Shipping methods, the system needs to send a request to the carrier’s server and fetch the response. The whole thing can take anything from 200 to 700 ms. The wait time quickly adds up to whole seconds your customers have to wait before they can act.

Removing the carriers you don’t use is easy and can possibly shave off 1-2 seconds of the loading time without writing a single line of code. Go to Stores > Configuration > Sales > Shipping Methods and remove carriers you don’t work with.

allowed carrier methods magento to speed up cart

4. Remove Estimated Shipping to Simplify Your Shopping Cart Page

Estimated Shipping is a good UX tool that helps you set customer expectations about pricing. Even so, if the Cart is too slow you can push this information one step further – towards the Checkout. This move will lift some burden off the server if your Cart is overloaded with functionality and you can’t balance it right.

DevDocs for Magento 2.3 tell us that in order to customize Checkout steps, you have to change checkout_index_index.xml (do it through custom module override, don’t change Magento Core directly). In our case, we want to get rid of a specific Knockout component inside the cart shipping block. 

According to DevDocs, you can disable Knockout components by passing componentDisabled option into their config section using layout instructions, it looks like this:


For our needs, the instructions will be:


In addition to checkout_index_index.xml, you need to remove or comment the following lines located in checkout/cart/shipping.phtml. Since it’s a bad idea to directly change Magento internals, you need to override this template file in your custom module/theme and remove the lines there. Without this step you’ll still see the header of a now obsolete block:


All done? Good job. One less thing to worry about.

5. Disable Unused Shopping Cart Rules

It sounds obvious but this tip offers a noticeable performance improvement. Apparently, Magento constantly checks for cart price rules before showing you the final amount. Naturally, a busy online store will have dozens of unused rules which slow down Magento Cart and Checkout speed.

cart_price_rules

Cleaning up all unused active rules offers a nice performance boost to both the Cart and Checkout. Just disable them and you are done here. Make sure you flush Magento cache to see the improvements.

6. Truncate Magento Database to Run Faster

Upgrading to a better Magento hosting can massively help you out but if you’ve done everything else here and still don’t see improvement, look closely at your database. 

Over time, reading these massive databases and adding new entries becomes slower and slower. One of the solutions is to backup and truncate the tables. This solution works best for larger stores with millions of entries that don’t hold a lot of value anymore.

Truncate and optimize the following database tables: 

  • dataflow_batch_export,
  • dataflow_batch_import,
  • log_customer,
  • log_quote,
  • log_summary,
  • log_summary_type,
  • log_url,
  • log_url_info,
  • log_visitor,
  • log_visitor_info,
  • log_visitor_online,
  • report_viewed_product_index,
  • report_compared_product_index,
  • report_event,
  • index_event,
  • Catalog_compare_item.

7. Optimize or Disable Extensions to Speed Up Magento Cart

Magento extensions that affect Add to Cart functionality, Magento Shopping Cart price rules, catalog rules, or add custom product options can severely slow down your Magento Cart.

There are two approaches you can take here. The hard one is to attempt to optimize the custom extension that interferes with the Cart performance. Reviewing and refactoring the code you have never seen before is not a trivial task even for an experienced developer.

If you have the option, just disable the extension in question and look for alternatives that don’t affect your Cart performance as much. After all, this extension can’t be the only one on the market.

8. Disable Minimum Advertised Price in Advanced Sales

Getting rid of complex pricing rules that you don’t use inside the store will help you alleviate some pressure off the Shopping Cart. When the system doesn’t need to check for an additional value in the database, this time can be spent on the actually important stuff.

One of these values people rarely use is MAP (Minimum Advertised Price). It’s a vital feature for some stores that can’t legally advertise a price that is lower than a price recommended by the manufacturer (commonly known as MSRP).

Anyways, most stores don’t need this feature and you can safely turn it off at Stores > Configuration > Sales > Sales.

disable minimum advertised price to speed up magento cart

9. Review All Add to Cart Events That Slow You Down

Let’s return to the theme of profiling once again. You need to carefully examine what happens when the user clicks Add to Cart. Some of the slowdowns are easier to catch using New Relic, Blackfire, and similar performance monitoring applications than Magento Profiler.

For example, in one of our cases, a third-party analytics module sent curl requests upon adding new products to the Shopping Cart. As you might expect, this additional heavyweight event significantly slowed down the cart for the users. We got rid of the slow-down effect only after properly rewriting these requests.

Summing Up Magento Add to Cart Issues

While you are investigating your Cart performance, bear in mind that a slow Magento Add to Cart functionality can have multiple origins. Even once your cart is working smoothly you can make sure to setup an abandoned cart flow to capture as many of those conversions as possible.

We’ve listed 9 most common solutions we use to deal with slow Magento Cart on a daily basis, no matter if your Magento 1.9 add to cart is slow or Magento 2.x. Even though these are quite effective, profiling Magento code for performance is the best way to find out bottlenecks and other speed issues which will be different from site to site.

Implemented all our recommendations and still can’t reach that <1-second performance mark on Magento Cart? Let’s discuss how you can achieve better speed with a talented team of Magento developers.

Magento tips from real projects
Magento tips from real projects
Close
CALL US 24/7:
Australia
& asia
+61 (02) 8005-7494