Assets & Media
Import images, videos, audio, and web fonts directly into your components with deterministic path-and-content hashing, HTTP byte-range media streaming, and ambient TypeScript support for 26 built-in formats.
Assets & Media in Dinou
In Dinou, media and font files imported into JavaScript, TypeScript, or CSS are treated as first-class module dependencies. When you import an asset (e.g. import logo from "./logo.png"), the active bundler (Esbuild, Rollup, or Webpack) and runtime engine:
- Fingerprints path + content: Computes a deterministic 8-character SHA-256 hash combining the normalized project-relative path and the file's binary bytes.
- Emits the asset: Writes the file to the public static distribution directory under
.dinou/dist3/assets/[name]-[hash].[ext](and.dinou/cloudflare/assets/assets/on Cloudflare Workers). - Returns a plain URL string: Resolves the import identically across RSC, SSR, and client bundles to the public URL (e.g.
"/assets/logo-8f1e2a4c.png").
immutable caches on file edits.dinou/env plus auto-generated types for custom assetExtensions in .dinou/types/routes.d.ts.Imported Assets vs. Public Directory
In Dinou, files imported inside your code (src/**/* or aliased directories) are processed by bundlers, fingerprinted with deterministic path-and-content hashes, and emitted into .dinou/dist3/assets/* with 1-year immutable caching. In contrast, files placed in public/ bypass bundlers entirely and are copied directly into the web root with fixed, unhashed URLs (ideal for favicon.ico, robots.txt, PWA manifests, and verification files).
Supported Extensions (26 Formats)
Dinou recognizes 26 media and font extensions out-of-the-box across images, video, audio, and web fonts:
| Category | Format Extensions | Served MIME Types |
|---|---|---|
| Images (8) | .png, .jpg, .jpeg, .gif, .svg, .webp, .avif, .ico | image/png, image/jpeg, image/gif, image/svg+xml, image/webp, image/avif, image/x-icon |
| Video (7) | .mp4, .webm, .mov, .avi, .mkv, .mjpeg, .mjpg | video/mp4, video/webm, video/quicktime, video/x-msvideo, video/x-matroska, video/x-motion-jpeg |
| Audio (6) | .mp3, .wav, .ogg, .flac, .m4a, .aac | audio/mpeg, audio/wav, audio/ogg, audio/flac, audio/mp4, audio/aac |
| Fonts (5) | .woff, .woff2, .ttf, .otf, .eot | font/woff, font/woff2, font/ttf, font/otf, application/vnd.ms-fontobject |
Usage in Server & Client Components
Importing media and font files works identically in both Server Components (RSC) and Client Components ("use client"). Imported assets resolve to fingerprinted URL strings that can be passed directly to standard JSX elements like <img>, <video>, <audio>, <link rel="preload">, or Web Audio APIs:
// src/components/avatar.tsx
import userAvatar from "./avatar.webp";
import defaultIcon from "./user-placeholder.svg";
export function UserAvatar({ hasCustomPhoto }: { hasCustomPhoto?: boolean }) {
const photoSrc = hasCustomPhoto ? userAvatar : defaultIcon;
return (
<div className="relative w-12 h-12 rounded-full overflow-hidden border">
<img
src={photoSrc}
alt="User profile avatar"
width={48}
height={48}
loading="lazy"
className="object-cover w-full h-full"
/>
</div>
);
}// src/components/media-hero.tsx
"use client";
import heroBgVideo from "./hero-ambient.mp4";
import heroWebmVideo from "./hero-ambient.webm";
import chimeAudio from "./welcome-chime.mp3";
export function MediaHero() {
const playSound = () => {
const audio = new Audio(chimeAudio);
audio.play().catch(() => {});
};
return (
<div className="relative h-96 flex items-center justify-center overflow-hidden rounded-2xl">
{/* Background Video with multiple format fallbacks */}
<video
autoPlay
muted
loop
playsInline
className="absolute inset-0 w-full h-full object-cover -z-10"
>
<source src={heroWebmVideo} type="video/webm" />
<source src={heroBgVideo} type="video/mp4" />
</video>
<div className="text-center text-white space-y-4 p-6 bg-black/40 backdrop-blur-sm rounded-xl">
<h2 className="text-3xl font-bold">Experience Dinou</h2>
<button
type="button"
onClick={playSound}
className="px-4 py-2 bg-emerald-600 hover:bg-emerald-700 text-white rounded-lg text-sm font-semibold transition shadow"
>
Play Welcome Chime
</button>
</div>
</div>
);
}// src/layout.tsx
import type { LayoutProps } from "./dinou";
import interVariable from "@/assets/fonts/inter-latin.woff2";
import "./globals.css";
export default function RootLayout({ children }: LayoutProps) {
return (
<html lang="en">
<head>
<link
rel="preload"
href={interVariable}
as="font"
type="font/woff2"
crossOrigin="anonymous"
/>
<link rel="stylesheet" href="/styles.css" precedence="default" />
</head>
<body>{children}</body>
</html>
);
}Path Aliases & CSS url() Assets
Dinou resolves path aliases configured in tsconfig.json or jsconfig.json (as well as bare node_modules asset specifiers) identically across Esbuild, Rollup, Webpack, and all server/edge engines:
// Path aliases from tsconfig.json / jsconfig.json
import companyLogo from "@/assets/brand/logo.svg";
import heroBanner from "@/assets/images/banner.webp";
// Package assets from node_modules
import interWoff2 from "@fontsource/inter/files/inter-latin-400-normal.woff2";Relative and aliased url(...) references inside stylesheets (such as @font-face or background-image) share the exact same fingerprinting pipeline, emitting a single deduplicated file in /assets/[name]-[hash].[ext] when an asset is referenced from both CSS and TSX. See the Styles documentation for full details on CSS asset handling.
Production Output, Caching & HTTP Range
When building for production (dinou build), Dinou emits all imported media and font files into .dinou/dist3/assets/ with sanitized names and 8-character path-and-content SHA-256 hashes:
.dinou/dist3/assets/
├── logo-4b2a8f1c.png
├── banner-9c1d3e72.webp
├── inter-latin-0f4e81b3.woff2
└── intro-sound-7e2f1a90.mp3- Immutable CDN & Browser Caching: Every file under
/assets/*is served withCache-Control: public, max-age=31536000, immutable. Replacing an image or video at the same source path produces a new hash automatically on the next build. - HTTP Byte-Range Streaming (
206 Partial Content): Dinou's development server and standalone Node.js, Bun, and Deno servers natively support RFC 9110Range: bytes=...requests withAccept-Ranges: bytes, enabling instant<video>and<audio>timeline scrubbing and native Safari media playback.
TypeScript Declarations (dinou/env)
Ambient type declarations for all 26 built-in media and font extensions are packaged directly into dinou/env.
Ensure that dinou-env.d.ts exists in your project root:
/// <reference types="dinou/env" />And include both dinou-env.d.ts and .dinou/types/**/*.d.ts in your tsconfig.json:
{
"compilerOptions": {
"target": "ES2022",
"rootDirs": [
"src",
".dinou/routes"
],
"paths": {
"@/*": [
"./src/*"
]
},
"allowJs": true,
"skipLibCheck": true,
"noEmit": true,
"jsx": "react-jsx",
"strict": true,
"module": "ESNext",
"moduleResolution": "bundler"
},
"include": [
"src",
"dinou-env.d.ts",
".dinou/types/**/*.d.ts"
]
}Extending Custom Formats (assetExtensions)
If your application imports specialized binary or 3D formats—such as .glb, .gltf, and .hdr for Three.js / WebGL scenes, or .wasm and .pdf—register them via assetExtensions in dinou.config.ts without ejecting:
// dinou.config.ts
import { defineConfig } from "dinou";
export default defineConfig({
// Leading dots are optional ("glb" and ".glb" both work)
assetExtensions: ["glb", "gltf", "hdr", "wasm"],
});Once added to dinou.config.ts:
- All 3 bundlers & all 5 runtimes (Esbuild, Rollup, Webpack, Node.js, Bun, Deno, Cloudflare Workers, and Netlify) automatically fingerprint and emit imports matching those extensions into
/assets/[name]-[hash].[ext]. - Automatic TypeScript Ambient Types: Running
npx dinou typegen(or startingdinou dev/dinou build) automatically generatesdeclare module "*.glb"declarations inside.dinou/types/routes.d.ts—no manual.d.tsboilerplate required.
If you have ejected Dinou, you can also inspect or customize the default 26 extensions directly in dinou/core/builtin-asset-extensions.js and dinou/assets.d.ts.