Vanilla Breeze v0.7.4

Vanilla Breeze v0.7.4 released

0.7.4 gives the Ambient pack weather. A page names one feed URL on its own site, and the pack sets data-weather from it, uses its sunrise and sunset for dawn and dusk, and never shows a stale observation. Helpers for producing the feed from Open-Meteo are included. Ambient p…

Read the release notes

include-file

Load remote HTML fragments with progressive enhancement. Fallback content shows until fetch completes.

Overview

The <include-file> component fetches a same-origin HTML fragment, sanitizes it, and inserts it. Any existing content serves as a fallback shown until the fetch completes (or if it fails).

Attributes

AttributeValuesDefaultDescription
srcstring—URL of the HTML fragment, resolved against the page (document.baseURI). Only same-origin http(s) URLs load; blob:, data:, javascript: and other schemes are always refused; other origins need allow-cross-origin. A same-origin URL that redirects off-origin is refused. Observed: changing it re-fetches (honouring lazy); a change made while detached loads on reconnect.
mode"replace", "append", "prepend"replaceHow fetched content is inserted. append/prepend leave existing children (including author scripts) untouched. Unknown values behave as replace and log a warning.
lazyboolean—Defer loading until the element is within 200px of the viewport (also for later src changes)
trustedboolean—Author vouches for the source: insert the fetched HTML without sanitizing. Without it the fragment goes through VB's sanitizer (no scripts, on* handlers, javascript: URLs, iframes, forms…). Never set it for URLs that serve user-generated content.
allow-scriptsboolean—Run the fragment's scripts (each once per load). Requires trusted; ignored with a console warning otherwise.
allow-cross-originboolean—Permit fetching from another origin (the server must allow it via CORS). Content is still sanitized unless trusted is also set.
data-label-errorstringFailed to load contentText of the role="alert" error message shown when a load fails and no fallback content remains

Lazy Loading

Add lazy to defer the fetch until the element scrolls into view (with a 200px root margin).

Insert Modes

Control how the fetched HTML is inserted with mode.

Events

EventDetailDescription
include-file:loaded{ src, url, html }After the fragment is inserted. src is the attribute value, url the resolved absolute URL, html the markup as inserted (sanitized unless trusted).
include-file:error{ src, error }When the fetch fails or the load is refused; error is a message string. The original fallback is restored on a first-load failure in replace mode.
include-file:src-changed{ src, source: 'property' }After .src is assigned a new value from script (not for direct attribute changes)

JavaScript API

Member Description
src Mirror of the src attribute. Assigning a new value loads it and fires include-file:src-changed.
reload() Re-fetch content from the current src (same policy checks as a normal load).

Security & Nesting

<include-file> is safe by default. Each relaxation is an explicit attribute the page author writes; content can never grant itself trust.

Same origin by default

src is resolved against the page (document.baseURI). Only http:/https: URLs on the page’s own origin load. blob:, data:, javascript: and other schemes are always refused, and a same-origin URL that redirects to another origin is refused too. Add allow-cross-origin to load from another origin; that server must also allow it with CORS.

Sanitized by default

Fetched HTML goes through the shared VB sanitizer before it is inserted, and the cleaned nodes are inserted directly (never re-parsed from a string). It removes <script>, <style>, <iframe>/<object>/<embed>, <form> and form-submission attributes, <base>, <meta>, <link>, SVG <foreignObject>, every on* event handler, srcdoc, javascript: and data: URLs on links and loaders, and script-bearing inline style. Partials keep their ids, names, safe inline styles and invoker attributes (popovertarget, commandfor), so first-party fragments such as a site header still work; a partial that relied on its own <style> block needs trusted or a stylesheet. The include-file:loaded event’s detail.html is the serialised sanitized fragment for inspection — do not re-insert it with innerHTML. Nested <include-file> elements keep their src but lose trusted, allow-scripts and allow-cross-origin, so they stay same-origin and sanitized. The sanitizer is not a full HTML policy engine: it blocks script execution, not styling or layout tricks.

trusted and allow-scripts

Set trusted when you control the source and need markup the sanitizer removes (forms, inline handlers, iframes). Scripts in the fragment run only with both trusted and allow-scripts; allow-scripts alone is ignored with a console warning. Each load runs only that fragment’s scripts, once; author scripts and earlier appended content are never re-run or removed. Never use trusted on a URL that serves user-generated content.

Cycles and depth

Fragments may contain further <include-file> elements. An include whose URL already appears among its ancestor includes (a fragment including itself, or A → B → A) is refused, as is nesting deeper than 10 levels. Both show the normal error state.

Relative URLs inside fragments

The fragment is parsed into the host page, so relative URLs inside it (links, images, nested src) resolve against the host page, not against the fragment’s own URL. Use root-relative URLs (/partials/…) in fragments that are included from more than one place.

Progressive Enhancement

Without JavaScript, the fallback content (whatever HTML is inside the element) remains visible and the src URL is never fetched. Make the fallback useful on its own, for example a link to the full page the fragment comes from, so nothing is silently missing.

Accessibility

  • Fallback content ensures content is always available.
  • aria-busy="true" is set while a fetch is in flight.
  • Content that changes after load (a src change or reload()) is not announced by default. Add aria-live="polite" to the element to opt in.
  • On failure the original fallback is restored (first load, replace mode). When no fallback remains, an error message renders as a real role="alert" paragraph; set its text with data-label-error.

Related

  • <iframe> — Embeds an entire document (heavier, sandboxed)
↑