Skip to main content

Varnish

Optimising website performance

C
Written by CiviPlus Helpdesk
Updated over a week ago

🧩 What is Varnish?

Varnish is a tool that helps your website load faster and handle more visitors. It does this by caching (storing) public pages so they don't have to be rebuilt by Drupal every time someone visits.

Faster, more reliable browsing.

Great for high-traffic events.


💡 Key Benefits

  • Fast performance: Pages load almost instantly.

  • Reliability: Cached pages are available during maintenance.

  • Lower server usage: Reduces backend strain for each visitor.


👥 Who Is This For?

This guide is designed for:

  • Site owners and admins who want faster performance.

  • Content editors who want to know how their updates appear.

  • Business users interested in reliability and uptime.


🔐 Access and Skills Needed

Access required:

  • Logged-out (anonymous) access to your website.

  • Incognito/private browsing to test.

Skills required:

✅ Basic browser skills
✅ Familiarity with Drupal editing
✅ Optional: Inspect → Network tab

❌ No server access or command line needed
❌ No need to understand caching internals


⚙️ How It Works

  1. A visitor loads a public page.

  2. If Varnish has it stored → it's shown immediately.

  3. If not → Drupal builds the page, and Varnish saves it for the next visitor.

  4. When content is updated, the cached version is cleared and refreshed.


📊 Before and After Comparison

Without Varnish

With Varnish

Pages are rebuilt every visit

Pages load from memory

High traffic slows the site

Site stays responsive

Maintenance blocks access

Cached pages stay visible

Server under constant load

Server focuses on new data


🧪 How to Check If Varnish Is Working

Method 1: Speed Test

  1. Open an Incognito window.

  2. Visit a public page (e.g., Homepage).

  3. Refresh 2–3 times.

  4. If it's faster on repeat loads → caching is working.

Method 2: Check Headers

You can use your browser's built-in tools to confirm whether a page is being served by Varnish.

Steps:

  1. Open a private/incognito window in your browser.

  2. Go to your website’s homepage (or any public page).

  3. Right-click anywhere on the page and choose “Inspect” or “Inspect Element”.

  4. Click the Network tab at the top of the inspector.

  5. Refresh the page (F5 or ⌘R).

  6. Click on the first item listed—usually the page URL itself.

  7. Under Headers, look for the Response Headers section.

via: 1.1 varnish (Varnish/6.0)
x-cache: HIT

🟢 x-cache: HIT means the page was served from cache.
🟡 x-cache: MISS on first load is normal — it gets cached after that.

If you see x-cache: MISS on the first load and then HIT after refreshing, that’s perfectly normal. The first load adds the page to the cache; the second one uses it.


🔄 How Varnish Handles Content Updates

  • When you update content (e.g. a page or image), Varnish automatically purges the old version.

  • The next visitor will get the updated version, and that is then cached.

🕒 Cached pages are stored for 1 day.


📌 What’s Cached and What’s Not

Type

Cached?

Notes

Public pages

✅ Yes

Fast loading

Forms / Webforms

❌ No

Dynamic, user-specific

Logged-in page views

❌ No

Always served fresh

POST requests

❌ No

Not cacheable

Session-based content

❌ No

Privacy protected


🧱 Special Page Types and Listings

⚠️ Some pages like blogs, news indexes, and anchor pages may not auto-purge when content is added or updated.

📌 If needed, we can manually configure these URLs to purge on updates.

Example: /news, /events, /blog, /resources


🛠 Maintenance Mode Behavior

If your site goes into maintenance mode, cached public pages:

  • Will continue to show to logged-out visitors

  • Until the cache expires (1 day), or is manually cleared

This ensures your key pages remain visible even during backend downtime.


✅ Summary

  • You don’t need to manage Varnish manually.

  • It works silently in the background, speeding up public browsing.

  • Logged-in editors always see the freshest version.

Did this answer your question?