PHPackages                             grimlink/magento-bfcache-patches - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. grimlink/magento-bfcache-patches

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

grimlink/magento-bfcache-patches
================================

Patches to enable and optimize Back/Forward Cache (BFCache) support in Magento 2

0.1.1(3w ago)611OSL-3.0

Since May 27Pushed 3w agoCompare

[ Source](https://github.com/GrimLink/magento-patch-bfcache)[ Packagist](https://packagist.org/packages/grimlink/magento-bfcache-patches)[ RSS](/packages/grimlink-magento-bfcache-patches/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependenciesVersions (3)Used By (0)

Magento 2 BFCache Patches
=========================

[](#magento-2-bfcache-patches)

This repository provides a collection of patches to enable and optimize **Back/Forward Cache (BFCache)** support in Magento 2. These patches are based on the work from [Magento 2 PR #40750](https://github.com/magento/magento2/pull/40750).

Why?
----

[](#why)

By default, Magento 2 prevents browsers from caching storefront pages in the Back/Forward Cache by sending `Cache-Control: no-store` headers. This means that every time a user clicks the "Back" or "Forward" button, the browser must re-fetch the page from the server and re-execute all JavaScript, leading to slower navigation and a less responsive experience.

**BFCache** allows the browser to save a complete snapshot of the page (including the JavaScript state) in memory. When a user navigates back, the page is restored instantly.

These patches improve Magento 2 by:

- **Removing restrictive headers:** Allowing the browser to utilize BFCache for storefront pages.
- **Handling state restoration:** Adding `pageshow` event listeners to refresh dynamic content (like the minicart, customer data, and authentication tokens) when a page is restored from cache.
- **Improving Performance:** Significantly boosting Core Web Vitals, specifically Largest Contentful Paint (LCP) and Interaction to Next Paint (INP) during history navigation.

How to Install
--------------

[](#how-to-install)

These patches work with any Composer-based patch tool, including [cweagans/composer-patches](https://docs.cweagans.net/composer-patches/) and [vaimo/composer-patches](https://github.com/vaimo/composer-patches). Choose the option that fits your setup.

### Option 1: Git Clone (Recommended)

[](#option-1-git-clone-recommended)

Clone this repository into a `patches` directory in your Magento root, move the `patches.json` to the root, and apply the patches:

```
git clone https://github.com/GrimLink/magento-bfcache-patches patches
mv patches/patches.json .
composer patches-relock
composer patches-repatch
```

### Option 2: Curl or Wget

[](#option-2-curl-or-wget)

Download and extract the patches, move the configuration file, and apply the changes:

**Using Curl:**

```
mkdir -p patches
curl -L https://github.com/GrimLink/magento-bfcache-patches/archive/refs/heads/main.tar.gz | tar -xz -C patches --strip-components=1
mv patches/patches.json .
composer patches-relock
composer patches-repatch
```

**Using Wget:**

```
mkdir -p patches
wget -O - https://github.com/GrimLink/magento-bfcache-patches/archive/refs/heads/main.tar.gz | tar -xz -C patches --strip-components=1
mv patches/patches.json .
composer patches-relock
composer patches-repatch
```

### Merging with Existing patches.json

[](#merging-with-existing-patchesjson)

If you already have a `patches.json` file in your project root, do not overwrite it. Instead, copy the entries from this repository's `patches.json` into your existing file and run the following commands to update your lock file and apply the new patches:

```
composer patches-relock
composer patches-repatch
```

### Option 3: Composer Require (vaimo/composer-patches)

[](#option-3-composer-require-vaimocomposer-patches)

If you are using [vaimo/composer-patches](https://github.com/vaimo/composer-patches) with package patch sources enabled, you can install this package directly via Composer and vaimo will pick up and apply the patches automatically.

```
composer require grimlink/magento-bfcache-patches
```

Warning

This method requires `vaimo/composer-patches` with package-level patch sources enabled. See the [vaimo/composer-patches documentation](https://github.com/vaimo/composer-patches) for the required configuration. If you are using `cweagans/composer-patches`, use [Option 1](#option-1-git-clone-recommended) instead.

### Option 4: Using the "Mage" Repository

[](#option-4-using-the-mage-repository)

If you are using the [GrimLink/mage](https://github.com/GrimLink/mage/) distribution or its tools, there is a built-in option to add this patch set automatically.

License
-------

[](#license)

These patches are licensed under the same terms as Magento 2 (OSL-3.0 / Apache-2.0).

###  Health Score

34

—

LowBetter than 75% of packages

Maintenance95

Actively maintained with recent releases

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity25

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~35 days

Total

2

Last Release

23d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/482de6cea25a4fe2d4b27d083cc439703e737d690d436a5009cc677d32109d25?d=identicon)[GrimLink](/maintainers/GrimLink)

---

Top Contributors

[![GrimLink](https://avatars.githubusercontent.com/u/4387541?v=4)](https://github.com/GrimLink "GrimLink (7 commits)")

---

Tags

bfcachemagento2magento2-patchperformancemagento2patchescore-web-vitalsbfcache

### Embed Badge

![Health badge](/badges/grimlink-magento-bfcache-patches/health.svg)

```
[![Health](https://phpackages.com/badges/grimlink-magento-bfcache-patches/health.svg)](https://phpackages.com/packages/grimlink-magento-bfcache-patches)
```

###  Alternatives

[webpatser/laravel-uuid

Laravel integration for webpatser/uuid - High-performance drop-in UUID replacements (15% faster than Ramsey). Provides Str macros, HasUuids trait, facades, and casts. RFC 4122/9562 compliant.

1.8k17.9M141](/packages/webpatser-laravel-uuid)[magepal/magento2-googletagmanager

Google Tag Manager (GTM) for Magento 2 with Advance Data Layer

2691.6M5](/packages/magepal-magento2-googletagmanager)[boldcommerce/magento2-ordercomments

Magento 2 Module to add a comment field above the place order button in the checkout

170768.1k](/packages/boldcommerce-magento2-ordercomments)[mageplaza/magento-2-blog-extension

Magento 2 Blog extension

121748.9k5](/packages/mageplaza-magento-2-blog-extension)[magepal/magento2-reindex

Reindex your Magento2 store quickly and easily from backend/admin, instead of command line.

108705.0k1](/packages/magepal-magento2-reindex)[rafaelcg/magento2-quicklink

Faster subsequent page-loads by prefetching in-viewport links during idle time

5115.9k](/packages/rafaelcg-magento2-quicklink)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
