In-App Notifications for Svelte Apps
Add a notification widget to your Svelte or SvelteKit app with one script tag. No Svelte SDK needed. Initialize in onMount, send from your backend, and deliver in real time via SSE. Lightweight like Svelte itself.
Why Notilayer for Svelte
Built to feel native in Svelte projects
No heavy dependencies. No framework lock-in. Just a script tag that works with Svelte's minimal philosophy.
No SDK to install
One script tag in app.html. No npm package, no Svelte wrapper, no build step changes. Keep your bundle lean.
Shadow DOM isolation
Widget renders in a Shadow DOM. Svelte's scoped styles, global CSS, and Tailwind classes will never conflict with the notification widget.
onMount lifecycle
Initialize in Svelte's onMount hook. The widget auto-connects to SSE for real-time notification delivery.
SvelteKit ready
Works with SvelteKit's SSR and SPA modes. Add to app.html, initialize in +layout.svelte, and you are done.
Lightweight by design
External async script. Zero impact on your Svelte bundle size. Matches Svelte's philosophy of shipping less JavaScript.
Auto-updates
The widget script is always the latest version. No npm update commands, no version pinning, no breaking changes to chase.
Step 1
Add the script tag to app.html
Open your src/app.html file and add the Notilayer widget script before the closing body tag. This is the HTML template that SvelteKit uses for every page. For plain Svelte with Vite, add it to your index.html instead.
- One line of HTML. No npm install.
- Loads asynchronously with
defer. No render blocking. - Persists across SvelteKit client-side navigations.
src/app.html
<!-- src/app.html -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
%sveltekit.head%
</head>
<body>
<div id="svelte">%sveltekit.body%</div>
<script
src="https://api.notilayer.com/widget/widget.js"
defer
></script>
</body>
</html> src/routes/+layout.svelte
<!-- src/routes/+layout.svelte -->
<script>
import { onMount } from 'svelte'
onMount(() => {
window.Notilayer.init({
projectId: 'YOUR_APP_ID',
userId: currentUser.id,
})
})
</script>
<slot /> Step 2
Initialize in onMount
Import onMount from Svelte and call window.Notilayer.init() with your project ID and user ID. This ensures the widget connects only on the client side, after the component mounts. Place it in your root +layout.svelte so it runs once for the entire app.
- onMount runs only in the browser -- safe for SSR
- Pass your user ID to show personalized notifications
- SSE connection opens automatically after init
Step 3
Send from your backend
Trigger notifications from any backend -- Node.js, Python, Go, or SvelteKit server routes. Make a POST request to the Notilayer API with the user ID, title, and body. The notification appears in the user's bell widget instantly via SSE.
Works with SvelteKit API routes
Call the Notilayer API from +server.ts endpoints or server-side load functions.
Any language, any backend
REST API works from Node.js, Python, Ruby, Go, or any language that speaks HTTP.
Real-time delivery
Notifications appear instantly in the Svelte app. No polling, no WebSocket setup.
Backend API call
// Send a notification from your backend
const res = await fetch('https://api.notilayer.com/v1/notify', {
method: 'POST',
headers: {
'Authorization': `Bearer ${process.env.NOTILAYER_API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
userId: 'user_123',
title: 'New comment on your post',
body: 'Sarah replied to your thread.',
}),
}) Compatibility
Works across the Svelte ecosystem
The widget is framework-agnostic by design. It works seamlessly with every Svelte project setup.
Svelte 4 & 5
Works with both Svelte 4 and Svelte 5 (runes mode). The widget does not depend on Svelte internals -- it is a standalone script.
SvelteKit
Add to app.html, initialize in +layout.svelte. Works with SSR, CSR, and prerendered pages. Survives client-side navigation.
Vite + Svelte
Using Svelte without SvelteKit? Add the script tag to index.html. Same behavior, same onMount initialization.
FAQ
Svelte integration questions
Do I need a Svelte package for Notilayer?
Does Notilayer work with SvelteKit?
Will the widget conflict with Svelte's scoped styles?
How do I show notifications in real time with Svelte?
Explore more: Home · Vue Notifications · Angular Notifications · React Bell · Next.js Notifications
Add Notifications to Your Svelte App
One script tag. No Svelte SDK. Real-time delivery. Free plan included.