In this post, we would like to raise the issue of Magento store optimization to help e-commerce owners improve their store operation and receive more traffic from search engines. We will provide some insights on online store loading speed issues, walk you through the most common mistakes people do while optimizing Magento and give practical recommendations you can apply right away or consider implementing in future.
Why to optimize and whether you need to do it at all?
The primary reason why you should care about store loading speed is that unless your website is getting completely loaded in a couple of seconds you’re probably losing visitors.
It is extremely important for people, actual humans visiting your website, to open the online page quickly. According to many studies, people leave quite fast if website is not loading.
In 2009 Shopzilla made redesign and experienced 120% increase from Google after the page speed boost
-1 second = +2% conversion
-100ms = +1% revenue
Google is continuously tracking page load times of every website and takes this information into consideration while evaluating rankings. They collect the data in two ways:
1. Google bot records the time it takes to open a web page.
2. Google’s browser, Chrome, anonymously sends information to Google about page load time.
Just as Google, your store server also likes optimized websites. The server loads better if the website is optimized. It means that potentially it will be possible to serve more visitors using fewer servers. Therefore, investment in optimization saves your hosting cost.
How to optimize?
There are several ways to do this, and it’s very important to understand that the actual perceived speed people see when they open the website is the compound result of several factors:
- Your front-end (your theme, HTML, CSS, JS, etc.).
- The actual back-end (which is Magento, the database that Magento is running on, server operating system, and so on).
- Network lying between (your server uses it to send information to browsers).
1. Latest Version
It is very important that you are always running the latest version of Magento as updates generally contain bug fixes and performance improvements. There are three major steps when it comes to upgrading a Magento installation.
1. Install a fresh version the Magento file tree (the version you are trying to upgrade to).
2. Run the installer from the file tree on top of the outdated database (thereby upgrading the database).
3. Move over themes and custom extensions from the old version to the current version.
Upgrading Magento is a little more work than upgrading WooCommerce or Shopify, but Magento has a good in-depth tutorial on how to fully upgrade Magento.
Magento also does a good job of notifying you of important updates that become available within your notifications/messages inbox (depending on which version of Magento you’re using.
2. Content Delivery Network
KeyCDN has a very simple integration with Magento and Magento 2. Both can be setup with HTTP and HTTPS configurations.
Latest trends in web development show that it is moving more and more towards the front-end. If you have a Magento website that has not really been built with the optimized front-end in mind, it is very likely you will have huge gains just by reviewing the front-end side and by doing optimization here.
1. Make your page visible before being fully loaded (it is always better to get at least some information while the other ‘heavy’ files are loading). To do this you need to compress:
2. Put all the small images (especially social media icons) into a single file. This is called “spriting” or “sprites”. When this file is downloaded the browser will show pieces of this file by simulating separate images out to one big image.
3. Desynchronize loading of each script like Google Maps, social networks etc. This recommendation could be applied to all elements that are not really important to be functional right away.
4. All JS that are not involved in webpage appearance should be placed at the bottom of the page (right before ) and all CSS should be placed at the top.
5. Specify the width and height of the images you have on your webpages – this will help the browser to understand how much space needs to be skipped for the image and it will continue to upload and show content. Otherwise the browser will concentrate on uploading the image and will not show the content below it.
4. Back-end optimization
Magento is resource-hungry – it’s a complex large system, so back-end is where Magento can be slow. In Magento back-end optimization you need to know the specific aspects to make your website much faster.
1. Due to the fact that Magento, by default, loads a big amount of same files upon every page request, you can use memory file systems like TMPFS on unix-based systems (Linux, for example) to speed up this process as much as possible and make those files accessible as fast as possible. You can use a full-page caching server, which will eliminate the request from coming to the server in the first place. You can also apply to things like Redis for sessions, and for cashing which will use memory instead of the disc space, and therefore you can speed up the file access. So, basically, you need to fine-tune the server to use its memory for maximum.
2. Minimize the number of DNS requests the browser needs to make. Browsers need to understand your IP address, which means they need to contact DNS. Then the website is transferred by http in the browser and you can influence these parts. You should minimize the number of external resources that need to be loaded, such as external scripts.
3. Compress the content. You need to make it the smallest possible using .gzip compression. And then – upload absolutely everything to an external static system (JS, style sheets etc.).
4. Set up «last-modified» and «if-modified-since». This helps browsers to understand when the page was modified last time and if it hasn’t changed it can be uploaded from browser cache.
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. MySQL Configuration
MySQL has its own “query cache” that it uses in Magento to help generate dynamic pages and content while improving performance. These are some recommended settings for your my.cnf file.
query_cache_type = 1
query_cache_size = 32M
And also a recommended setting for php.ini.
php_value memory_limit 512M
7. PHP Accelerators
Using a PHP accelerator is another form of caching. They increase performance of PHP scripts by caching them in their compiled state. You can use a PHP accelerator like APC, ZendOptimizer+ or Xcache.
- APC – http://pecl.php.net/package/APC
- Xcache – http://xcache.lighttpd.net/
- eAccelerator – http://eaccelerator.net/
To conclude, the main idea of this post was to show you that you should invest in hosting. Cheap shared hosting is not good enough for Magento. You need at least a small dedicated server in order to actually use Magento as something that is supposed to be fast and therefore useful for both you and your business.
As you can see there are many ways you can speed up your Magento eCommerce site. From implementing a CDN to caching, enabling flat catalog, image optimization, merging CSS and JS files, using the Magento Compiler, and cleaning up your database. Also having a good web host is equally important.
Do you have another way to speed up Magento that we missed? We would love to hear about it below in the comments.
Article by : Tapas Ranjan Panda
Sr. Magento Developer
Linkedin | Stackoverflow