Magento 2 speed up optimization is quite an important step when seeking to increase traffic to your store. Sometimes store owners pay a lot of attention to design, sales, or social media marketing activities, but completely forget about site performance. It's important to remember that the site speed forms the first impression, and that's hard to change. Find out more information about speeding up Magento 2 in our blog post 5 reasons to speed up your Magento 2 store.
1. Magento 2 System Requirements
The server is the core, and if the particular server you picked is not functioning smoothly, you won't have good website speed, regardless of what efforts you make, and all other tips from this or other articles.
Before starting performance optimization in Magento 2, we strongly suggest that you place your store on the dedicated server. While selecting a 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
PHP OPcache: PHP OPcache is strongly recommended to be enabled for performance reasons. The OPcache is enabled in many PHP distributions. To verify that it's been 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 the 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. (I got the sense there was some missing words or punctuation to distinguish the different technologies listed)
2. Enable Flat Categories and Products
One of the top reasons for Magento speed issues is database read speed.
To quicken the read speed of the database, you should enable Flat Catalog. This will reduce the number of joins (joins between tables) when showing products. Due to this, the MySQL query complexity will be reduced.
Go to backend, STORES -> Configuration -> CATALOG -> Catalog -> Use Flat Catalog Category and put in “Yes”
3. Merge CSS and JS Files
Huge CSS and JS files: apart from making your frontend look fancy, they 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 it actually helps your visitors load pages faster as a result.
There are many types of CDNs, just look through the 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 can find a set up for it: STORES -> GENERAL -> Configuration -> Web -> Base URLs (Secure)
Caching can significantly speed up Magento 2 on the localhost, too. Magento 2 has a variety of caching options, and here's where you can find them: SYSTEM -> Cache Management
Here you will find caching options of your Magento store. Click on those that you need, select Enable option and click Submit Page Cache, and you will significantly reduce server response time and total page load time as result.
But M2 creates a cache instance for each page (categories, products, etc) only after visiting this page and usually the cache lifetime is 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 best suits your needs. For a Magento 2 ecommerce speed up with a tremendous amount of product images, it is even more crucial not to overload the site. The suggestion we have for you is as follows: use JPEG format for Product images. It is way more suitable for pictures than other formats as you can compromise quality for a reduced size. On the other hand, using PNG or SVG for layout and logo is way more beneficial, so use each 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's 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 more enjoyable.
- Implement CDN for your store – Magento 2 supports it out-of-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.