
Product
Introducing Repository Access Permissions and Custom Roles
Socket now supports Custom Roles and Repository Access Permissions so organizations can control who can access specific repositories and actions.
@nexus_js/head
Advanced tools
Nexus Head — reactive SEO metadata manager for Islands Architecture.
In an islands architecture most of your page is static HTML. Interactive pieces are isolated "islands". But SEO metadata (<title>, og:image, description, canonical, JSON-LD...) still lives in <head>.
Nexus Head gives you two clean ways to manage it:
defineHead() called from load() is automatically collected and injected into the final HTML by the renderer. Perfect for crawlers and zero-JS pages.useHead() inside a <script> reactively updates the head when your Svelte runes change.In any load() (page or layout) simply return a head object. The renderer will pick it up, call defineHead for you, and inject the tags (replacing <!--nexus:head--> or injecting before </head>).
// src/routes/+page.nx or +layout.nx
export async function load(ctx) {
return {
head: {
title: 'My Page',
description: 'Best page ever',
canonical: 'https://example.com/page',
og: { image: 'https://example.com/og.png', type: 'website' },
twitter: { card: 'summary_large_image' },
},
// ... other pretext data
};
}
No need to touch the layout template for per-page metadata.
Layouts + pages are merged (child wins).
Return partial head objects from layouts and let pages override specific keys:
// +layout.nx
export async function load(ctx) {
return {
head: {
titleTemplate: '%s | My Site',
og: { siteName: 'My Site', type: 'website' },
twitter: { site: '@mysite' },
},
};
}
// +page.nx
export async function load(ctx) {
return {
head: {
title: 'Blog Post',
description: 'A great read',
og: { type: 'article', image: 'https://example.com/cover.png' },
},
};
}
Merged result: title becomes "Blog Post | My Site", og:type is "article" (page wins), og:siteName is preserved from the layout.
For advanced cases or inside server-only blocks:
---
import { defineHead } from '@nexus_js/head';
defineHead({
title: 'Product',
og: { image: product.image },
});
---
When passing ctx you get request-scoped isolation (safe for concurrent streaming):
defineHead({ title: '...' }, ctx);
Inside islands that hydrate on the client:
<div client:load>
<script>
let count = $state(0);
useHead(() => ({
title: `Counter: ${count.value}`,
}));
</script>
...
</div>
useHead cleans up previously injected elements on every re-run, so you never leak old <meta> tags.
| Property | Type | Description |
|---|---|---|
title | string | Page <title>. Also sets og:title and twitter:title automatically. |
titleTemplate | string | Template with %s placeholder: `"%s |
description | string | <meta name="description">. Mirrored to og:description and twitter:description. |
canonical | string | <link rel="canonical">. Also sets og:url. |
robots | string | RobotsDirective | Index/follow directives. |
viewport | string | Viewport meta (usually set once in the root layout). |
og | OpenGraphMeta | title, description, image, imageAlt, imageWidth, imageHeight, url, type, siteName, locale. |
twitter | TwitterMeta | card, site, creator, title, description, image, imageAlt. |
jsonLd | object | object[] | JSON-LD structured data injected as <script type="application/ld+json">. |
links | LinkTag[] | Arbitrary <link> tags. |
metas | MetaTag[] | Arbitrary <meta> tags. |
scripts | ScriptTag[] | <script> tags to inject into <head>. |
themeColor | string | <meta name="theme-color">. |
favicon | string | <link rel="icon"> href. |
All string values are HTML-escaped automatically (<, >, &, ").
defineHead(meta: HeadMeta, ctx?) — server only. Push metadata to the stack.flushHead(ctx?) — returns and clears collected metas.renderHeadToString(metas) — turns metas into a safe HTML string.useHead(() => meta) — client reactive.All are re-exported from @nexus_js/server for convenience.
defineMetadataThe old defineMetadata (from @nexus_js/server) is deprecated. Replace it with either:
head return value from load() (recommended).defineHead() if you need imperative control.MIT © Nexus contributors
FAQs
Nexus Head — reactive SEO metadata manager for Islands Architecture
The npm package @nexus_js/head receives a total of 35 weekly downloads. As such, @nexus_js/head popularity was classified as not popular.
We found that @nexus_js/head demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Socket now supports Custom Roles and Repository Access Permissions so organizations can control who can access specific repositories and actions.

Product
Socket MCP now lets AI assistants review org alerts, investigate threats using the Socket threat feed, and inspect package files in addition to dependency scoring.

Product
Socket Firewall blocks malicious VS Code and Open VSX extensions before install, protecting developers from compromised editor marketplaces.