A slow Magento 2 store is a costly problem. Research shows that 53% of mobile users abandon sites that take more than 3 seconds to load, and every 1-second improvement in load time can boost conversions by 7%. For UK eCommerce merchants, speed isn't optional โ it's a competitive necessity.
In this guide, we'll cover every optimisation technique available for Magento 2 stores, from server-level caching to code-level improvements. Whether you're aiming for a 90+ Lighthouse score or just want your pages to stop frustrating customers, this is your roadmap.
1. Choose the Right Theme: Hyva Over Luma
Before anything else โ if you're on Magento's default Luma theme, the single most impactful speed improvement you can make is migrating to Hyva Theme. Hyva's JavaScript bundle is 12x smaller than Luma's (65KB vs 800KB+), and it's specifically engineered for performance.
We cover this in detail in our Hyva vs Luma comparison. If you're serious about performance, Hyva migration should be your first consideration. Our team at Magento Services handles these migrations regularly.
2. Full-Page Cache with Varnish
Magento 2 includes built-in full-page cache (FPC), but configuring it with Varnish as the cache backend delivers dramatically better results. With a properly configured Varnish setup, cached page requests are served in under 100 milliseconds.
# Example Varnish VCL snippet for Magento 2
sub vcl_recv {
# Pass requests with session cookies
if (req.http.cookie ~ "PHPSESSID") {
return (pass);
}
return (hash);
}
Key Varnish configuration steps for Magento 2:
- Install and configure Varnish 7.x (recommended for Magento 2.4.x)
- Generate Magento's VCL file:
bin/magento varnish:vcl:generate - Configure cache lifetime appropriately for your store's content update frequency
- Set up proper cache invalidation to clear when products/pages update
3. Redis for Session and Cache Storage
Replace Magento's default file-based session and cache storage with Redis. Redis is an in-memory data store that delivers much faster read/write operations.
Configure Redis in your env.php for both the default cache backend and session storage. A typical Magento 2 production setup should use separate Redis instances for page cache, default cache, and sessions.
4. Elasticsearch / OpenSearch Configuration
Magento 2.4.x uses Elasticsearch (or OpenSearch) as the default search engine. Proper configuration significantly impacts both search speed and indexing performance:
- Allocate sufficient heap memory (at least 1GB for production)
- Configure appropriate shard counts for your catalog size
- Use search result caching for popular queries
- Schedule regular index rebuilds during off-peak hours
5. CDN Implementation
A Content Delivery Network (CDN) serves static assets (images, CSS, JavaScript) from servers geographically close to your visitors. For UK stores serving customers across the country and Ireland, a CDN typically reduces static asset load times by 40โ60%.
Popular CDN options for UK Magento 2 stores:
- Cloudflare โ Excellent free tier, DDoS protection, simple Magento 2 integration
- Fastly โ Magento Commerce's recommended CDN, deep integration available
- AWS CloudFront โ Good for stores already on AWS infrastructure
- BunnyCDN โ Cost-effective option with good UK/EU edge locations
6. Image Optimisation
Images are often the largest contributors to page weight. For Magento 2:
- Enable WebP format delivery โ Magento 2.4.x supports WebP natively
- Configure proper image dimensions in your theme โ avoid serving 2000px images scaled down via CSS
- Use lazy loading for below-fold images
- Compress images before upload (use tools like Squoosh or ImageOptim)
- Consider a responsive image solution for different device breakpoints
7. Database Optimisation
Magento 2's MySQL database is frequently a performance bottleneck, especially for large catalogues:
- Run
bin/magento indexer:reindexregularly and schedule automatic reindexing - Clean the
report_eventandcatalog_product_flattables periodically - Add MySQL query cache and optimise
my.cnfsettings for your server's RAM - Use the
EXPLAINcommand to identify slow queries - Archive old order data to a separate table to keep primary tables small
8. PHP OpCache and PHP-FPM Tuning
PHP configuration has a significant impact on Magento 2 performance:
- Enable and properly configure OPcache (cache all Magento PHP files)
- Set
opcache.memory_consumptionto at least 512MB for production - Tune PHP-FPM pool settings based on your server's CPU cores and RAM
- Use PHP 8.2 or 8.3 (significant performance improvements over PHP 7.x)
9. JavaScript and CSS Minification/Bundling
Magento 2 includes built-in JS/CSS minification and merging. Enable these in production:
- Admin โ Stores โ Configuration โ Advanced โ Developer โ JavaScript Settings โ Merge JS Files: Yes
- Admin โ Stores โ Configuration โ Advanced โ Developer โ CSS Settings โ Merge CSS Files: Yes
- Enable JS bundling (but test carefully โ can sometimes cause issues)
- For Hyva stores, Tailwind CSS purging automatically removes unused styles
10. Hosting Environment
Even the best-optimised Magento 2 code will underperform on inadequate hosting:
- Use SSD storage (NVMe preferred) โ significantly faster than traditional HDDs
- Ensure sufficient RAM (minimum 8GB for a production Magento 2 store)
- Use managed Magento hosting providers (Nexcess, Cloudways, Hypernode) for better defaults
- Choose a data centre location in the UK or EU for best performance for UK visitors
Measuring Your Improvements
Always measure before and after any optimisation. Key tools:
- Google PageSpeed Insights โ Core Web Vitals and Lighthouse scores
- GTmetrix โ Detailed waterfall analysis
- WebPageTest โ Real browser testing from multiple locations
- New Relic / Blackfire.io โ Application performance monitoring for deep PHP profiling
If you need professional help optimising your Magento 2 store's performance, our team at Magento Services UK offers comprehensive speed audits and optimisation services. We've helped dozens of UK merchants achieve 90+ Lighthouse scores. You can also see more of our work at magento-services.com.
Need a Speed Audit?
Our team will audit your Magento 2 store and provide a detailed report with prioritised recommendations.
Request Speed Audit โ Our Speed Services