Magento performance
How to speed up Magento 2: the complete performance guide
Server tuning, frontend fixes, code-level work and monitoring: every layer of Magento 2 speed, with a checklist you can work through.
On this page
Magento 2 is powerful but demanding. Without optimization, stores slow to a crawl under load. A slow store loses customers: Google ranks it lower, and conversion rates drop as pages slow down.
This guide covers every layer of Magento 2 optimization: server, frontend, code and monitoring. You will finish with an actionable checklist to speed up your store.
Server-level optimization
Enable Varnish HTTP caching
Varnish sits between your server and browsers and caches entire pages. A properly configured Varnish cuts TTFB (time to first byte) sharply on cached pages and serves many more concurrent users without adding servers.
- Install and configure Varnish 6.0+
- Set the cache TTL to suit each page type (typically 3600 seconds for product pages)
- Purge specific URLs when the catalog changes
- Exclude logged-in users from the cache (Magento handles this with cookies)
Use Redis for sessions and caching
Redis replaces file-based session storage with in-memory caching. This reduces database load and speeds up session lookups.
- Configure Redis for session storage: the connection string lives in
env.php - Configure Redis for the general cache: use a separate Redis instance for stability
- Monitor Redis memory usage and set eviction policies
- Enable Redis persistence if data loss is unacceptable
Tune OpenSearch
Magento 2.4 requires OpenSearch or Elasticsearch for catalog search. A well-tuned search engine speeds up search and layered navigation.
- Use OpenSearch 2.x (or a supported Elasticsearch version)
- Adjust the search engine heap size (typically
-Xmx2g -Xms2g) - Tune query boost factors for relevance
- Monitor query latency and adjust sharding if needed
Our RoomService360.com build, a large Magento 2 catalog on Hyvä, runs on this same stack of Varnish, Redis and Elasticsearch.
Frontend optimization
Implement lazy loading
Lazy loading defers images until the user scrolls near them. This cuts initial page weight and bandwidth.
- Add the
loading="lazy"attribute to images - Use the Intersection Observer API for custom lazy loading
- Lazy-load off-screen iframes
- Test on a 4G mobile connection to confirm perceived performance improves
Optimize images
Images are typically 50 to 80% of page weight, so optimizing them pays off quickly.
- Use modern formats: WebP with a JPEG fallback
- Compress aggressively with tools like TinyPNG or ImageOptim
- Serve responsive images with
<picture>andsrcset - Generate thumbnails at the size you display (don’t serve 3000px images in a 300px slot)
- Use an image CDN such as Cloudflare Image Optimization or ImageKit
Use a content delivery network (CDN)
A CDN caches static assets (CSS, JS, images) at edge locations near your users, which removes geographic latency.
- Use Cloudflare, AWS CloudFront or Fastly
- Cache CSS, JS, images and fonts with long TTLs (1 year)
- Bust caches with query strings or versioned file names
- Enable compression (gzip, Brotli)
Minify and bundle CSS and JavaScript
- Minify CSS and JS (strip whitespace, shorten variable names)
- Bundle related scripts to reduce HTTP requests
- Defer non-critical JavaScript such as analytics and third-party widgets
- Inline the critical CSS for above-the-fold content
Code-level optimization
Optimize database queries
Slow database queries are the most common performance bottleneck in Magento.
- Use the MySQL slow query log to find bottlenecks
- Add database indexes on frequently filtered columns
- Use collection filters instead of loading every item into memory
- Avoid nested loops and N+1 queries (use joins instead)
- Monitor query time in New Relic or Datadog
Plan your reindex strategy
Magento’s indexing is powerful but can block the site while it runs.
- Schedule indexing for low-traffic periods
- Use partial reindexing where possible and avoid full reindexes
- Monitor indexing time and optimize custom indexers
- Disable indexers your store doesn’t need
Optimize product listing pages
Product listing pages often load hundreds of SKUs with images and filters, a common performance killer.
- Paginate: show 20 to 40 items per page, not 100
- Lazy-load filter options
- Use faceted search (OpenSearch or Algolia) instead of plain filters
- Load images as WebP with fallbacks
Monitoring and measurement
Monitor continuously
You can’t optimize what you don’t measure.
- New Relic: real-time application performance monitoring, transaction tracing and alerting
- Datadog: infrastructure monitoring and APM with custom dashboards
- GTmetrix: waterfall analysis and PageSpeed scoring
- Google PageSpeed Insights: Core Web Vitals (LCP, INP, CLS)
- Magento Performance Toolkit: built-in load testing
Set a baseline and track progress
- Measure baseline performance before optimizing
- Set targets, for example pages that load in under 2 seconds and a PageSpeed score of 90+
- Optimize one layer at a time and measure the impact
- Use monitoring alerts to catch regressions immediately
To start from a measured baseline, a free Magento store audit measures page speed, Core Web Vitals and server response before anything changes.
Magento speed optimization checklist
- Varnish HTTP caching enabled and configured
- Redis for sessions and cache
- OpenSearch configured and tuned for the catalog size
- Lazy loading on images
- Images optimized (WebP, compressed, responsive)
- CDN enabled for static assets
- CSS and JS minified and bundled
- Database queries optimized (slow query log reviewed)
- Indexing strategy reviewed and optimized
- Product listing pages paginated and optimized
- Monitoring in place (New Relic, Datadog or similar)
- Core Web Vitals tracked (Google PageSpeed, GTmetrix)
What results can you expect?
Working through this guide should move your store in these directions. How far depends on your catalog, extensions and hosting, which is why we measure before and after on every store:
- Page load time: lower, especially on category and product pages
- PageSpeed and Core Web Vitals: higher scores and more URLs passing
- Conversion: faster pages give shoppers fewer reasons to leave
- Infrastructure: better caching means fewer requests reach your servers
- Capacity: more concurrent shoppers on the same hardware
Next steps
You don’t have to do this alone. Performance work takes testing, monitoring and iteration. We do this work every week on client stores.
Our Magento performance optimization service covers every layer above. Start with a free audit to see where your store stands and which fix will have the biggest impact.