PHPackages                             bagisto/bagisto-varnish - 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. [Framework](/categories/framework)
4. /
5. bagisto/bagisto-varnish

ActiveLibrary[Framework](/categories/framework)

bagisto/bagisto-varnish
=======================

A Bagisto package that integrates Varnish Cache for enhanced performance with full-page caching and dynamic content handling.

v2.0.0(1mo ago)91163[1 issues](https://github.com/bagisto/bagisto-varnish/issues)[1 PRs](https://github.com/bagisto/bagisto-varnish/pulls)MITPHP

Since Sep 17Pushed 1mo ago2 watchersCompare

[ Source](https://github.com/bagisto/bagisto-varnish)[ Packagist](https://packagist.org/packages/bagisto/bagisto-varnish)[ RSS](/packages/bagisto-bagisto-varnish/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)DependenciesVersions (5)Used By (0)

Varnish Integration for Bagisto
===============================

[](#varnish-integration-for-bagisto)

This package integrates **Varnish Cache** with Bagisto to boost site performance by delivering cached pages quickly, while still supporting **dynamic components** through **ESI (Edge Side Includes)** or **AJAX-based dynamic views**.

---

📌 Features
----------

[](#-features)

- ⚡ **Full-page caching** via Varnish
- 🔄 **Automatic cache purging** on product, category, or content updates
- 🔍 **ESI support** for dynamic blocks
- 🖱 **AJAX-based dynamic view loading** for improved Core Web Vitals
- 🛠 **Artisan commands** for cache management
- 🖥 **Admin tools** for purging cache &amp; exporting VCL
- 🎨 **Theme-ready Blade components**
- 🛡 **Middleware for cache headers** (cacheable &amp; non-cacheable routes)

---

🔄 Request Flow
--------------

[](#-request-flow)

[![image](https://private-user-images.githubusercontent.com/26001046/476577895-c0f2186d-6f73-47d8-a26e-c6f49cafa983.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnV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EYXRlPTIwMjYwNDAyVDExMTAxMVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTRhNWJjMjgwMzI2M2Y2NTM3ZWQ0ZTUwYTdlMzI3MjNkMmVjZWQ4MGMzZjExZWU1NWNmMTQxMjNlMTkyOWRmZDImWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.0EhTjuR3wMDLf0hd4AIvTFc68Jo2PfRDiD_wo9OxGts)**Explanation**:

- **443 (HTTPS)** → **Nginx** handles SSL termination and forwards traffic.
- **80 (HTTP)** → **Varnish Proxy** caches and serves pages, or passes the request to the backend.
- **8080** → **Bagisto** (Laravel app) generates fresh content when needed.

**Flow Summary**: Browser → Nginx → Varnish Proxy → Bagisto → Response (cached or fresh)

---

📦 Installation
--------------

[](#-installation)

### 1. Install via Composer

[](#1-install-via-composer)

```
composer require bagisto/bagisto-varnish
```

### 2. Register the Service Provider

[](#2-register-the-service-provider)

In `bootstrap/providers.php`:

> **Note:** Autoloading via Composer’s package auto-discovery is **not possible** for this provider. The registry order matters—`VarnishServiceProvider` must be listed **after** the Shop package or at the end of the providers array. Auto-discovery would load it too early, which can cause issues.

```
'providers' => [
    Webkul\Varnish\Providers\VarnishServiceProvider::class,
],
```

### 3. Publish Assets &amp; Config

[](#3-publish-assets--config)

```
php artisan vendor:publish --provider="Webkul\Varnish\Providers\VarnishServiceProvider"
```

---

⚙️ Varnish Server Configuration
-------------------------------

[](#️-varnish-server-configuration)

1. Install **Varnish 6.x** on your server.
2. Replace `/etc/varnish/default.vcl` with the provided file:

    ```
    Varnish/vcls/6.0.vcl

    ```
3. Restart Varnish:

    ```
    sudo systemctl restart varnish
    ```

---

🎨 Theme Integration
-------------------

[](#-theme-integration)

You can integrate dynamic content in **two ways**:

---

### **1 – Define Dynamic Views / Fragments**

[](#1--define-dynamic-views--fragments)

In `config/varnish.php`, define a **key** (identifier) and its corresponding **Blade view path**:

```
return [
    'esi' => [
        'views' => [
            ...

            'customer-desktop-dropdown' => 'varnish::shop.components.layouts.header.desktop.customer-dropdown',

            ...
        ]
    ],
];
```

- **Key** → Used in ESI or AJAX call (`customer-desktop-dropdown`)
- **Path** → Full Blade view path to render (`varnish::...`)

---

### **2 – ESI Include**

[](#2--esi-include)

```

```

- Injects content at the **Varnish level** (server-side).
- Appears immediately on page load.
- May affect LCP/FCP if the backend is slow.

---

### **3 – AJAX Dynamic View (Recommended for LCP)**

[](#3--ajax-dynamic-view-recommended-for-lcp)

```

```

- Loads via AJAX **after user interaction**.
- Improves LCP/FCP.
- Ideal for non-critical dropdowns, modals, and menus.

---

🗂 Cache-Control Headers
-----------------------

[](#-cache-control-headers)

For **routes that should NOT be cached** by Varnish:

```
Cache-Control: no-cache, no-store, must-revalidate

```

For **routes that should be cached**:

```
Cache-Control: public, max-age=604800, s-maxage=604800

```

*(Example: 7 days)*

---

### Middleware for Cache Headers in Bagisto

[](#middleware-for-cache-headers-in-bagisto)

We’ve created a middleware `Webkul\Varnish\Http\Middleware\VarnishCache` to handle cache headers.

Attach it to routes like this:

```
Route::get('/', [HomeController::class, 'index'])
    ->name('shop.home.index')
    ->middleware('cache.response');
```

---

🛠 UI Configuration (Export VCL)
-------------------------------

[](#-ui-configuration-export-vcl)

Navigate to: **Admin → Configuration → Cache Management → Varnish → Configuration**

Select **Varnish** as the cache application, then provide the following:

1. **Access List** – IPs allowed to purge the cache (e.g., `localhost`).
2. **Varnish Host URL** – Varnish server IP and port for purging/banning cache via UI.
3. **Backend Host URL** – Laravel Bagisto server IP used in the exported VCL.
4. **Backend Host Port** – Laravel Bagisto server port used in the exported VCL.
5. **Grace Period** – Duration for serving stale content if the backend is slow or unavailable.

---

🛠 Cache Management
------------------

[](#-cache-management)

Navigate to: **Admin → Configuration → Cache Management → Varnish → Purge Cache**

1. **Purge by URLs** – Enter full URLs (comma-separated) to clear specific cache entries. Paths and domains must match exactly.
2. **Purge Everything** – Clears **all** cache entries from Varnish. Use with caution, as it may temporarily affect performance.

---

🛡 Automatic Cache Purging
-------------------------

[](#-automatic-cache-purging)

The package automatically purges cache when:

- Products, categories, pages, orders, reviews, refunds, or theme changes occur.

You can also manually trigger purging by adding your own events in `EventServiceProvider` and calling:

```
VarnishCache::forget($urls);
```

---

🖥 Admin Panel Tools
-------------------

[](#-admin-panel-tools)

- **Purge Full Cache**
- **Purge by URL**
- **Export VCL**

---

🚀 Best Practices
----------------

[](#-best-practices)

- Use **ESI** for small, critical personalized blocks (e.g., login status, cart count).
- Use **AJAX dynamic views** for non-critical interactive elements to improve Core Web Vitals.
- Set **Cache-Control headers** with appropriate TTL values to control caching behavior.
- Always test on a staging environment before deploying to production.
- Monitor **LCP**, **FCP**, and **TTFB** after enabling Varnish.

###  Health Score

41

—

FairBetter than 89% of packages

Maintenance87

Actively maintained with recent releases

Popularity20

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity38

Early-stage or recently created project

 Bus Factor1

Top contributor holds 90.3% 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 ~92 days

Total

3

Last Release

54d ago

Major Versions

v1.1.0 → v2.0.02026-03-20

### Community

Maintainers

![](https://www.gravatar.com/avatar/680982d0f4253ee1f7df370dc28852fe08dd6aab0cfae16f45d6ea026fdfbd02?d=identicon)[devansh.bawari419@webkul.com](/maintainers/devansh.bawari419@webkul.com)

---

Top Contributors

[![devansh-webkul](https://avatars.githubusercontent.com/u/68321766?v=4)](https://github.com/devansh-webkul "devansh-webkul (28 commits)")[![navneetkumar-pim-webkul](https://avatars.githubusercontent.com/u/26001046?v=4)](https://github.com/navneetkumar-pim-webkul "navneetkumar-pim-webkul (3 commits)")

---

Tags

frameworklaravelcachevarnishbagistofull page cache

### Embed Badge

![Health badge](/badges/bagisto-bagisto-varnish/health.svg)

```
[![Health](https://phpackages.com/badges/bagisto-bagisto-varnish/health.svg)](https://phpackages.com/packages/bagisto-bagisto-varnish)
```

###  Alternatives

[hemp/presenter

Easy Model Presenters in Laravel

247592.6k1](/packages/hemp-presenter)[rahulalam31/laravel-abuse-ip

Block ip address of all spammer's around the world.

27431.5k](/packages/rahulalam31-laravel-abuse-ip)

PHPackages © 2026

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