Skip to content

Debug Toolbar

The debug toolbar is a visual overlay injected by the theme worker when debug mode is active. It shows real-time cache stats, per-section detail, and a live feed of purge events — all without leaving the page.

Add ?lk-debug=1 to any page URL:

https://your-site.layerkick.com/?lk-debug=1

This sets a cookie, so subsequent page loads stay in debug mode. Remove it with ?lk-debug=0 or clear the lk-debug cookie.

Debug mode enables:

  • The visual debug toolbar (bottom pill + panels)
  • Console logging via window.lk API
  • The ?lk-fresh=1 cache bypass (only works with debug cookie set)

A fixed bar at the bottom center of the page. Always visible in debug mode.

ElementDescription
Status dotGreen (≥80% hit rate), yellow (≥50%), red (<50%)
LK brandConfirms the debug bar is active
Cached ratioe.g. “12/14 cached” — sections served from cache vs total
Hit ratePercentage of sections served from cache
Render timeTotal server-side render time for uncached sections

Hover the pill to reveal the action bar.

Appears on hover above the pill. Five buttons:

ButtonAction
SectionsOpens the sections panel
EventsOpens the events panel (badge shows unseen event count)
PagePurges the current page’s cached sections. Click once to arm (3s countdown), click again to confirm
SitePurges all cached sections site-wide. Click once to arm (5s countdown), click again to confirm
FreshReloads the page with ?lk-fresh=1 to bypass section cache entirely

Slides in from the right. Shows every section rendered on the page:

  • Cache dot — green (HIT) or red (MISS)
  • Section type — e.g. hero, header, product-information
  • HIT / MISS badge — whether the section was served from cache
  • Render time — milliseconds spent in executeComponent() (0ms for cache hits)
  • Size — HTML output size in bytes

Click any section row to:

  1. Scroll the page to the matching [data-lk-section] element
  2. Show a colored overlay border (green = cached, red = miss) with a label badge
  3. Click the same row again or a different row to clear

Each section row has a purge button (circular arrow icon). Clicking it:

  1. Sends a POST /api/cache/purge with the section path
  2. Shows a spin animation while purging
  3. Displays a toast on completion

Slides in from the right. Shows a live feed of cache purge events.

The panel polls GET /__dev/purge-events?since=<timestamp> every 5 seconds. New events trigger a yellow toast notification and increment the badge counter on the Events button.

Each event shows:

  • Type badgepath, key, d1, or full
  • Paths affected — which URLs or keys were purged
  • Sections / keys evicted — counts of cache entries removed
  • Timestamp — when the purge occurred
  • Duration — how long the purge took

The event buffer is in-memory per Worker isolate. If a purge webhook hits a different isolate than the one serving your debug bar poll, those events won’t appear. This is expected for local dev — the feed isn’t guaranteed to be complete.

The debug toolbar extends the existing window.lk API with a .bar namespace:

window.lk.bar.toggle("sections") // toggle sections panel
window.lk.bar.toggle("events") // toggle events panel
window.lk.bar.highlight(0) // highlight first section
window.lk.bar.highlight(3) // highlight fourth section
window.lk.bar.clear() // clear section highlight
window.lk.bar.toast("Hello!", "green") // show a toast (green/yellow/blue)

The existing window.lk console API (cache stats, section list, etc.) continues to work alongside the toolbar.

The toolbar’s purge buttons call the existing POST /api/cache/purge endpoint. For local dev, CACHE_PURGE_TOKEN must be set in wrangler.toml:

[env.dev.vars]
CACHE_PURGE_TOKEN = "dev-debug-token"

This is already configured. The toolbar reads the token from the server-injected data — no manual auth needed.

GET /__dev/purge-events?since=<timestamp>&limit=<n>

Returns recent purge events as JSON. Gated by the debug cookie.

ParamDefaultDescription
sinceOnly return events after this Unix timestamp (ms)
limit50Maximum events to return

Response is an array of PurgeEvent objects, newest first.

FileRole
cf-client-site/src/lib/debug-bar.tsBuilder — assembles CSS + DOM + JS
cf-client-site/src/lib/debug-bar-css.tsScoped CSS (all under #lk-debug)
cf-client-site/src/lib/debug-bar-js.tsClient-side JS — pill, panels, events, highlighting
cf-client-site/src/lib/purge-events.tsIn-memory ring buffer for purge events
cf-client-site/src/render/page-renderer.tsCollects SectionDebugInfo per section
cf-client-site/src/worker.tsInjects debug bar HTML + serves event endpoint