Magento 2 speed optimization is quite an important step to reach good traffic to your store. Learn more about reasons in this post.
1. Magento 2 System Requirements
The server is the core. And in case the one you picked is not functioning smoothly, you won’t have good website speed nevertheless your efforts and all other tips from this or another article.
Before start Magento 2 performance optimization we strongly suggest you placing your store on the dedicated server. While choosing the host, run a check on these categories:
- Use the dedicated server or VPS, do not pick shared hosting option;
- Check the following System Requirements for Magento 2:
Operating systems: Linux x86-64. Linux distributions such as RedHat Enterprise Linux (RHEL), CentOS, Ubuntu, Debian, etc
Composer: Latest stable version. Composer is required for developers who wish to contribute to the Magento 2 codebase or anyone who wishes to develop Magento extensions.
Web servers: Apache 2.2 or 2.4. In addition, the apache mod_rewrite module must be enabled. mod_rewrite enables the server to perform URL rewriting. For more information, see our Apache documentation. NGINX 1.8 (or latest mainline version).
Database: MySQL 5.6 (Oracle or Percona)
PHP: 5.6.x 5.5.x, where x is 22 or greater 7.0.2 (supported by Magento version 2.0.1 and later only)
Required PHP extensions: bc-math curl gd, ImageMagick 6.3.7 (or later) or both intl mbstring mcrypt mhash openssl PDO/MySQL SimpleXML soap xml xsl zip PHP 7 only: json
Database: MySQL 5.6 (Oracle or Percona)
PHP OPcache: PHP OPcache is strongly recommended to be enabled for performance reasons. The OPcache is enabled in many PHP distributions. To verify if it is installed, see our PHP documentation for CentOS or Ubuntu. If you must install it separately, see the PHP OPcache documentation.
PHP settings: Particular PHP configuration settings, such as memory_limit, that can avoid common problems when using Magento are recommended.
SSL: A valid security certificate is required for HTTPS. Self-signed SSL certificates are not supported. PayPal: You must use libcurl version 7.34 or later for Transport Layer Security (TLS) version 1.2 support required by PayPal.
Mail server: Mail Transfer Agent (MTA) or an SMTP server
Magento can utilize the following technologies:: Redis version 3.0 for page caching Varnish version 3.5 or latest stable 4.x version for page caching Memcached latest stable version for session storage with either Memcache or Memcached PHP extensions (latest stable version) Magento Enterprise Edition (EE) only: Apache Solr 4.x RabbitMQ 3.5; Three master databases.
Optional but recommended: MySQL 5.6 (Oracle or Percona)
Database: php_xdebug2.2.0 or later (development environments only; can have an adverse effect on performance); PHPUnit (as a command-line tool) 4.1 or later
2. Enable Flat Categories and Products
One of the top reasons for Magento speed issues with database read speed.
To fasten the read speed of the database you should enable Flat Catalog. This will reduce the number of joins (joins between tables) when showing products and due to that, the MySQL query complexity will be reduced.
Go to backend, STORES -> Configuration -> CATALOG -> Catalog -> Use Flat Catalog Category and put “Yes”
3. Merge CSS and JS Files
Huge CSS and JS files apart from making your frontend look fancy can drop your website loading speed. Luckily, there is a way to lessen their influence in Magento 2.
- Go to backend, STORES -> Configuration -> ADVANCED -> Developer -> CSS Settings
- Merge CSS Files -> Yes
- Minify CSS Files -> Yes
Don’t forget to press Save Config after you are done!
Also, you can apply more effective solutions to reduce the number of JS/CSS files.
4. Content Delivery Network
CDN, or Content Delivery Network, is an interconnected system of cache servers that use geographical proximity as criteria for delivering web content and actually helps your visitors to load pages faster as a result.
There are many types of CDNs, just look through features provided, geo coverage and choose the one you like.
One of the Magento 2 features is out-of-the-box support of CDN and here’s where you may find set up for it: STORES -> GENERAL -> Configuration -> Web -> Base URLs (Secure)
Magento 2 has a variety of caching options, here’s where you can find them: SYSTEM -> Cache Management
Here you will find caching options of your Magento store, click on the ones you need, select Enable option and click Submit Page Cache can significantly reduce server response time and total page load time as result.
But M2 creates cache instance for each page (categories, products, etc) only after visiting this page and usually cache lifetime less one day.
Magento 2 module Page Cache Warmer can automatically visit pages without cache and warms cache for these pages.
6. Images Optimization
Before any image upload, make sure it’s compressed – there is no need for huge images beyond your layout capabilities.
Also, pick the format that suits most of your needs. For eCommerce, with a tremendous amount of product images, it is even more crucial not to overload the site. The suggestion we have for you: use JPEG format for Product images. It is way more suitable for pictures than other formats as you can compromise quality for less size. On the other hand, using PNG or SVG for layout and logo is way more beneficial. So use accordingly!
If you already use
.png images for catalog, you can reduce image size using
pngquant utility (it reduce image size up to 80%).
This simple command will compress all .png images in the
for file in `find pub/media/ -type f -name '*.png'`; do echo $file;pngquant $file --output $file -f;done
7. Magento Updates
Tiny simple tip: do not forget to update your store. Magento team is constantly working hard on improvements in performance, so don’t miss out on any!
Let’s sum up the key points:
- Don’t forget to enable flat products and categories to ease the MySQL queries.
- Merge CSS and JS files to make the user experience enjoyable.
- Implement CDN for your store – Magento 2 supports it out-from-the-box.
- Have caching enabled.
- Do not overload your website with high-quality images where it is not necessary.
- Don’t forget about your CMS updates.