Skip to main content

How Rendering Works

PRISM intercepts incoming HTTP requests and decides whether to render them through a headless Chrome pipeline or proxy them directly to the origin. This page describes the full request flow from arrival to response.

Request Flow​

Client Request
│
▼
┌─────────────┐ no ┌────────────────┐
│ Bot Detection├────────────►│ Proxy to Origin │
└──────┬──────┘ └────────────────┘
│ yes
▼
┌─────────────┐ no ┌────────────────┐
│Route Matching├────────────►│ Proxy to Origin │
└──────┬──────┘ └────────────────┘
│ yes
▼
┌──────────────┐
│Render Decision│─── cache hit ──► Return cached HTML
└──────┬───────┘
│ cache miss
▼
┌──────────────────┐
│ Acquire Chrome Tab│
└──────┬───────────┘
│
▼
┌──────────────────┐
│ Navigate to │
│ origin URL │
└──────┬───────────┘
│
▼
┌──────────────────┐
│ wait_for event │ (load / networkidle / selector)
└──────┬───────────┘
│
▼
┌──────────────────┐
│ Auto-Scroll │ Trigger intersection observers
└──────┬───────────┘
│
▼
┌──────────────────┐
│ post_wait_js │ Optional DOM fixups
└──────┬───────────┘
│
▼
┌──────────────────┐
│ Origin check │ Still the site's page?
└──────┬───────────┘
│
▼
┌──────────────────┐
│ HTML Extraction │ document.documentElement.outerHTML
└──────┬───────────┘
│
▼
┌──────────────────┐
│ Postprocessing │ lol_html transforms (strip scripts, etc.)
└──────┬───────────┘
│
▼
┌──────────────────────┐
│ Content Validation │ min_html_bytes, min_text_length, require_title
└──────┬───────────────┘
│ pass
▼
┌──────────────────┐
│ Cache & Respond │
└──────────────────┘

Step-by-Step Breakdown​

1. Bot Detection​

PRISM inspects the User-Agent header against a list of known search engine crawlers, social media bots, and link previewers. In bot-only mode (the default), only bot requests proceed to rendering. In render-all mode, every matching request is rendered.

2. Route Matching​

The request path is matched against the configured routes.include and routes.exclude glob patterns. Static assets, API endpoints, and other non-HTML paths are excluded by default and proxied directly to the origin.

3. Render Decision​

PRISM checks:

  • Is the request method GET or HEAD? (Other methods are proxied directly.)
  • Is the license valid?
  • Is the route included?
  • Is it a bot (in bot-only mode)?

Only when all conditions pass does PRISM proceed to rendering.

4. Cache Lookup​

Before rendering, PRISM checks the in-memory cache. Cache keys include the normalized URL (tracking params stripped, query params sorted) and, when viewport-aware rendering is enabled, the device class suffix (::mobile or ::desktop).

  • HIT -- return cached HTML immediately.
  • STALE -- serve stale content, trigger a background re-render.
  • MISS -- proceed to render. Concurrent requests for the same URL are coalesced so only one Chrome tab is used.

5. Chrome Tab Acquisition​

A tab is acquired from the Chrome tab pool. If all tabs are busy, the request queues up to pool.queue_max, for at most pool.queue_timeout_secs. If the queue is full or the wait expires, PRISM returns a 503 with Retry-After. The render timeout (timeout_secs) starts only once a tab has been acquired.

6. Navigation​

PRISM navigates Chrome to the origin URL with an X-Prism-Bypass header to prevent render loops. Chrome's HTTP cache is disabled to avoid 304 responses with empty bodies on reused tabs. CSP is bypassed to allow HTML extraction via document.documentElement.outerHTML. The bypass token and the [cache] vary headers go to every request the page makes to its own origin; the crawler's Accept header goes to the document request only, so the page's own API calls keep the Accept they set.

7. Wait Strategy​

PRISM waits for the page to be ready using the configured wait_for strategy:

ValueBehavior
loadWait for the load event (default)
networkidleWait for the loading indicators to clear, then until no request has been in flight for 500ms (at most 5 seconds)
domidleWait for the loading indicators to clear only; never looks at the network
CSS selectorWait until the given element appears in the DOM

If the selector never appears, the network never goes quiet, or the wait runs into render.timeout_secs, the render continues but is marked incomplete: PRISM logs a warning with the URL and reason, counts it in prism_render_incomplete_total, and, if render.incomplete_ttl_secs is set, keeps it in the cache for less time than a finished page.

8. Auto-Scroll​

After the wait, PRISM scrolls the page from top to bottom in 400px increments with 100ms delays. This triggers intersection observers that many SPAs use for lazy loading product grids, images, and infinite scroll content. If the scroll starts any network request, PRISM then waits up to 3 seconds for those requests, and only those, to finish, so the content they fetch is in the output. A request that was already in flight before the scroll does not hold this wait. Scrolling after the wait, not before, means the page has already built what there is to scroll.

9. post_wait_js​

If configured, PRISM executes custom JavaScript after scrolling and any wait that follows it. This is useful for DOM fixups on SPAs with lazy hydration -- for example, removing hidden classes from mega menus that React has not removed yet.

10. Is it still the site's page?​

Immediately before extraction PRISM reads location.origin and compares it with the origin it navigated to (scheme, host and port), or with the origin of server.public_base_url when that is set. A page whose JavaScript sent the browser somewhere else, such as single sign-on or a geo redirect, is not this site's page, and storing it would serve another site's HTML under your URL.

When the origins differ, nothing is cached and the crawler receives the origin's own response for the request, with x-prism-fallback: left-origin. It is not counted as a render failure and does not affect the circuit breaker. It is counted in prism_render_left_origin_total, and PRISM logs a warning, at most once a minute, naming the URL and where the document went. The fix is to exclude the route from rendering or, if the other origin is your own public address, to set server.public_base_url. A same-origin history.pushState or an HTTP redirect from the origin is unaffected: the first keeps the origin, and the second is answered as a redirect before this point.

11. HTML Extraction​

PRISM evaluates document.documentElement.outerHTML to capture the fully rendered DOM as an HTML string. When the live document has a doctype, it is serialised in front of the html element (normally <!DOCTYPE html>), so crawlers do not parse the page in quirks mode. A page without a doctype is served without one.

12. Postprocessing​

The extracted HTML is processed through lol_html (Cloudflare's streaming HTML rewriter) to strip scripts, event handlers, hydration attributes, comments, and noscript tags, and to resolve lazy images. See the Postprocessing page for details.

13. Status Code Resolution​

The HTTP status code is captured from Chrome's navigation response. Unless status_from_meta is turned off, PRISM also checks for SPA-signaled status codes via window.__PRISM_STATUS__ or a status <meta> tag such as <meta name="prism:status" content="404">. See Status Codes for details.

14. Content Validation​

If enabled, PRISM validates the rendered HTML against quality thresholds (min_html_bytes, min_text_length, require_title). Failures cause a fallback to the origin response without tripping the circuit breaker. See Content Validation.

15. Caching​

Valid rendered HTML is stored in the in-memory cache with the configured TTL. For 5xx responses, the error_ttl_secs setting controls whether and for how long errors are cached.

16. Response​

The rendered HTML is returned with appropriate headers:

  • X-Prism-Cache: HIT, MISS, STALE, or BYPASS
  • X-Prism-Render-Time: render duration in milliseconds (on cache miss)
  • X-Prism-Variant: bot-mobile, bot-desktop, human-mobile or human-desktop
  • Preserved origin headers: Cache-Control, Content-Language, X-Robots-Tag, Content-Security-Policy, X-Frame-Options, Strict-Transport-Security, Link

Error Handling​

When rendering fails (timeout, Chrome crash, circuit breaker open), PRISM falls back to proxying the request directly to the origin. The circuit breaker tracks consecutive failures and temporarily halts rendering attempts to avoid cascading failures.