Magento 2 Varnish Boost: Stripping Tracking Parameters for Superior Cache Performance

Boost Your Magento 2 Performance: The Critical Varnish Update for Cache Optimization

As e-commerce migration experts at Shopping Mover, we constantly emphasize the critical role of performance in Magento 2 success. One of the most impactful tools for achieving lightning-fast load times is Varnish Cache. However, even with Varnish in place, subtle issues can undermine its effectiveness, leading to slower sites and a compromised user experience. A recent Magento 2 GitHub issue (#40815) highlights a significant update aimed at resolving one such pervasive problem: cache fragmentation caused by marketing and tracking parameters.

The Silent Performance Killer: Tracking Parameters and Cache Fragmentation

Every Magento store leverages various marketing and analytics platforms – Google Ads, Meta (Facebook/Instagram), Adobe Marketing Cloud, HubSpot, Klaviyo, and numerous affiliate networks. These platforms often append unique query string parameters to URLs (e.g., utm_source, gclid, fbclid, _ke). While essential for tracking campaign performance, these parameters are irrelevant to the actual page content. From Varnish's perspective, a URL with a unique tracking parameter is a distinct page, even if the underlying content is identical. This leads to what's known as 'cache fragmentation' – Varnish ends up caching multiple versions of the same page, drastically reducing the cache hit ratio and negating much of Varnish's performance benefits.

The Solution: Expanding Varnish's Parameter Strip List

The core of this Magento 2 update is a proactive expansion of the list of marketing and tracking query string parameters that Varnish should strip from incoming requests before attempting to serve a cached page. This fix targets the vcl_recv subroutine within Magento's provided Varnish Configuration Language (VCL) files (specifically varnish4.vcl, varnish5.vcl, varnish6.vcl, and varnish7.vcl).

The proposed change significantly broadens the scope of parameters to be ignored, covering a vast array of platforms. New additions include:

  • Google: _ga, _gl, gdf*, gad_source, gbraid, wbraid, srsltid
  • Meta: igshid
  • Adobe: ef_id, s_kwcid, sc_cid
  • Matomo/Piwik: mtm_*, matomo_*, pk_*, piwik_*
  • HubSpot: hsa_*
  • Klaviyo: _ke
  • Affiliate Networks: tduid, campid, customid
  • Mailchimp: mc_*
  • Branch.io: _branch_match_id
  • Pinterest: epik
  • Dotdigital: dm_i
  • Amazon Ads: mk***
  • Generic/Multi-platform: ref, clickId, pcrid, trk_*, cm, cn, cs, si, tg, and more.

By stripping these parameters, Varnish sees identical URLs for identical content, ensuring a higher cache hit ratio and consistent page delivery.

Benefits for Magento Merchants and Developers

This update brings substantial benefits:

  • Improved Cache Hit Ratio: More requests will be served directly from Varnish, reducing the load on the Magento application.
  • Faster Page Load Times: A higher cache hit ratio directly translates to quicker page delivery for end-users.
  • Enhanced SEO: Search engines favor faster websites, and consistent URLs without extraneous parameters can also aid in crawling and indexing.
  • Reduced Server Load: Less work for the Magento backend means more stable performance during peak traffic.
  • Simplified Varnish Management: Magento's core VCLs will now be more robust, requiring less manual intervention for common tracking parameters.

This fix underscores Magento's ongoing commitment to performance optimization. For any Magento 2 store leveraging Varnish, ensuring your VCL configuration is up-to-date with these expanded stripping rules is a crucial step towards maximizing your site's speed and efficiency.

Start with the tools

Explore migration tools

See options, compare methods, and pick the path that fits your store.

Explore migration tools