Speed Up Magento: Caching and Performance Optimization
A fast Magento webshop is essential for a good user experience and higher conversions. In this guide, we explain how to optimize your Magento installation for maximum performance.
Why Speed Matters
- Better user experience: Visitors leave slow websites
- Higher conversions: Faster pages mean more sales
- Better SEO: Google rewards fast websites
- Lower server load: Efficient caching reduces resource usage
Built-in Magento Cache
Cache Types
Magento has several cache types:
| Cache Type | Description |
|---|---|
| Configuration | System configuration |
| Layouts | Page layouts |
| Blocks HTML output | HTML blocks |
| Collections Data | Database collections |
| Reflection Data | API interfaces |
| Database DDL | Database schema |
| EAV types and attributes | Entity attributes |
| Full Page Cache | Complete pages |
| Translations | Language files |
Enable All Cache
- Go to System > Cache Management
- Select all cache types
- Choose Enable from the dropdown
- Click Submit
Flush Cache
After making changes:
- Go to System > Cache Management
- Click Flush Magento Cache
- For more thorough cleaning: Flush Cache Storage
Manage Cache via SSH
The command line is faster. Run these commands in the Magento directory:
# show the status of all cache types
bin/magento cache:status
# enable all cache types
bin/magento cache:enable
# clean specific cache types only
bin/magento cache:clean config layout
# flush all cache
bin/magento cache:flush
Full Page Cache (FPC)
Full Page Cache is the most important for performance.
Built-in FPC
- Go to Stores > Configuration > Advanced > System
- Under Full Page Cache:
- Caching Application: Built-in Cache
- TTL for public content: 86400
Varnish (Recommended for Production)
Varnish is faster than built-in cache:
- Install Varnish on your server
- In Magento: Stores > Configuration > Advanced > System
- Caching Application: Varnish Cache
- Export VCL configuration
- Configure Varnish with exported VCL
Redis for Session and Cache
Why Redis?
- Faster than file-based storage
- Better for multi-server setups
- Reduces disk I/O
Configure Redis for Cache
In your app/etc/env.php:
'cache' => [
'frontend' => [
'default' => [
'backend' => 'Magento\\Framework\\Cache\\Backend\\Redis',
'backend_options' => [
'server' => '127.0.0.1',
'port' => '6379',
'database' => '0'
]
]
]
]
Configure Redis for Sessions
'session' => [
'save' => 'redis',
'redis' => [
'host' => '127.0.0.1',
'port' => '6379',
'database' => '1'
]
]
Index Optimization
Indexer Modes
- Update on Save: Real-time, but slower
- Update by Schedule: Faster, uses cron
Set Schedule Mode
- Go to System > Index Management
- Select all indexers
- Choose Update by Schedule
- Click Submit
Or via SSH:
bin/magento indexer:set-mode schedule
bin/magento indexer:status
Manual Reindex
Via command line:
bin/magento indexer:reindex
Production Mode
Run Magento in production mode for the best performance:
bin/magento deploy:mode:set production
bin/magento deploy:mode:show
In production mode, static files are generated in advance and visitors do not see error messages (they only go to the logs). After changes to your theme or extensions, deploy the static content again:
bin/magento setup:static-content:deploy en_US
After installing or updating extensions, run bin/magento setup:di:compile first. In developer or default mode, add -f to force the deployment.
Image Optimization
Enable Lazy Loading
Images only load when visible on screen, improving initial page load.
Resize Images
- Go to Stores > Configuration > Advanced > System
- Under Image Optimization
- Enable image resizing
Use WebP Format
WebP images are smaller than JPEG/PNG:
- Install a WebP module
- Configure automatic conversion
- Serve WebP to supported browsers
JavaScript and CSS Optimization
Merge and Bundle
-
Go to Stores > Configuration > Advanced > Developer
-
Under JavaScript Settings:
- Merge JavaScript Files: Yes
- Enable JavaScript Bundling: Yes (test thoroughly)
- Minify JavaScript Files: Yes
-
Under CSS Settings:
- Merge CSS Files: Yes
- Minify CSS Files: Yes
Move JS to Footer
- Move JavaScript to bottom of page
- Improves perceived loading speed
Database Optimization
Regular Maintenance
Clean up old data:
- Old quotes (abandoned carts)
- Log tables
- Old sessions
Query Optimization
- Find slow queries via the MySQL slow query log (the query cache no longer exists in MySQL 8.0)
- Optimize slow queries
- Add indexes where needed
CDN Integration
Benefits of CDN
- Faster static file delivery
- Reduced server load
- Global distribution
Configure CDN
- Go to Stores > Configuration > General > Web
- Under Base URLs for Static View Files
- Enter your CDN URL
Monitoring Performance
Tools
- Google PageSpeed Insights: Free analysis
- GTmetrix: Detailed performance report
- New Relic: Server-side monitoring
Key Metrics
- Time to First Byte (TTFB)
- Largest Contentful Paint (LCP)
- Total Blocking Time (TBT)
Performance Checklist
- Production mode enabled
- Full Page Cache active
- Static content deployed
- Indexers in schedule mode
- Magento cron runs every minute
- LiteSpeed Cache configured
- PHP OPcache enabled
Need Help?
We are here for you! If you run into any issues or have questions, our support team is happy to help you personally. Send us a message through the ticket system - we usually respond within a few hours and are happy to assist you.
Looking for web hosting? See what we offer.
0 of 0 found this helpful