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.
123
<include-file src="/partials/newsletter-form.html" trusted allow-scripts> <p><a href="/newsletter/">Sign up for the newsletter</a></p></include-file>
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.