# `preload` — `` hint generation _(no submodules)_ ## Purpose `generatePreloadHints` derives an ordered list of `` hints from a packed manifest, and `injectPreloadHints` appends those hints to a document's `
`. Together they let the Service Worker (or a one-off bootstrap script) preload critical packed entries before the browser's HTML parser would have requested them. These helpers are PACKER-BROWSER-18's production surface. They are pure and feature-detected — `injectPreloadHints` is safe to call from a Service Worker context (`document` is `undefined`) and will simply return an empty array. ## Features - `preload: true` selection (default) or descending-priority top-N - Stable tiebreak for ties: lexicographic ordering on `url` - `as` defaults to `"fetch"` when absent — preserves correct dispatch - `crossOrigin` pass-through to the emitted `` - OTel `fetchTotal` increments when an observability bundle is supplied ## Usage: Basic ```ts import { generatePreloadHints, injectPreloadHints, } from "@suaveplan/packer-browser/preload"; const hints = generatePreloadHints({ entries: [ { url: "/hero.image.packed", preload: true, as: "image" }, { url: "/font.woff2", preload: true, as: "font" }, ], }); injectPreloadHints(document, hints); ``` ## Usage: Advanced ```ts import { createPackerBrowserObservability } from "@suaveplan/packer-browser"; const observability = createPackerBrowserObservability({ meter }); const topThree = generatePreloadHints( { entries: [ { url: "/a.packed", priority: 1 }, { url: "/b.packed", priority: 5 }, { url: "/c.packed", priority: 3 }, ], }, { topN: 3, observability } ); // emits 3 fetchTotal increments ``` ## API Reference - `generatePreloadHints(manifest, opts?): readonly PreloadHintLink[]` - `manifest.entries: ReadonlyArray