Icons
How icons reach the page without a third-party request, how the server render draws them, and how to add an icon collection.
The browser never asks a third party for an icon, so a Content-Security-Policy needs no exception for the Iconify API. Icons reach the page in two ways:
- Bundled. Nuxt UI's client bundle holds every icon that its scanner finds in the workspace. The scanner reads the Vue, Markdown and YAML files, and the TypeScript of each layer's
app/directory, which includesapp.config.tsand itsui.iconsmappings. The bundle also holds Nuxt UI's own default icons. A page of a visitor who is not signed in does not load the bundle until the visitor acts on the page (a click, a key or a touch) or starts a visit, which waits for it. The sign-in page draws its icons from the ones its server render sends. A signed-in page loads the bundle before it shows. - Served. The frontend server serves every other icon, such as a page icon that a backend module declares.
GET /api/_dms/icons/<prefix>.json?icons=<name>,…answers in the Iconify API format from the collections installed in the workspace.ajs dms devandajs dms startrun the same server, so both serve the route.
$ curl -sI "http://localhost:3001/api/_dms/icons/lucide.json?icons=house" | grep -iE "^HTTP|content-type|cache-control"
HTTP/1.1 200 OK
content-type: application/json
cache-control: public, max-age=604800, stale-while-revalidate=86400
Collections
The workspace ships @iconify-json/lucide and @iconify-json/ph. A module that uses another collection depends on its @iconify-json/<prefix> package, or on @iconify/json. The route answers 404 for an unknown collection, and 400 for a name outside Iconify's naming rule.
Server rendering
The server render draws every icon, bundled or not. The frontend server loads each installed @iconify-json/* collection once and hands it to the renderer. An icon is therefore drawn in its first render once its data has loaded, instead of after the component mounts. The page carries the data of each icon that the render drew, so the browser draws the same icons as it hydrates. An icon that no installed collection holds stays empty on the server, and the browser fetches it.
One sprite per page
Each icon is drawn once per page. A hidden <svg id="dms-icon-sprite"> holds one <symbol> per icon, and one per flip or rotation of it. Every occurrence of the icon is an <svg> with a <use> of that symbol, so an icon repeated on each row of a table is sent once. The browser draws icons the same way, and adds the symbols of the icons it draws later to the same sprite.