
# Assets

> Configure how public and server assets are served and bundled.

::note
All examples on this page assume the following import in `nitro.config.ts`:

```ts
import { defineConfig } from "nitro";
```
::

### `serveStatic`

- Type: `boolean`{lang=ts} | `'node'`{lang=ts} | `'inline'`{lang=ts}
- Default: depends on the deployment preset used.

Serve `public/` assets in production.

**Note:** It is highly recommended that your edge CDN (Nginx, Apache, Cloud) serves the `.output/public/` directory instead to enable compression and higher level caching.

```ts
export default defineConfig({
  serveStatic: "node", // serve static assets using Node.js
});
```

### `noPublicDir`

- Default: `false`{lang=ts}

If enabled, disables `.output/public` directory creation. Skips copying `public/` dir and also disables pre-rendering.

```ts
export default defineConfig({
  noPublicDir: true, // skip public directory output
});
```

### `publicAssets`

Public asset directories to serve in development and bundle in production.

If a `public/` directory is detected, it will be added by default, but you can add more by yourself too!

It's possible to set Cache-Control headers for assets using the `maxAge` option:

```ts
export default defineConfig({
  publicAssets: [
    {
      baseURL: "images",
      dir: "public/images",
      maxAge: 60 * 60 * 24 * 7, // 7 days
    },
  ],
});
```

The config above generates the following header in the assets under `public/images/` folder:

`cache-control: public, max-age=604800, immutable`

The `dir` option is where your files live on your file system; the `baseURL` option is the folder they will be accessible from when served/bundled.

:read-more{to="/docs/assets"}

### `compressPublicAssets`

- Type: `boolean`{lang=ts} | `{ gzip?: boolean, brotli?: boolean, zstd?: boolean }`{lang=ts}
- Default: `false`{lang=ts}

If enabled, Nitro will generate a pre-compressed (gzip, brotli, and/or zstd) version of supported types of public assets and prerendered routes
larger than 1024 bytes into the public directory. Default compression levels are used. Using this option you can support zero overhead asset compression without using a CDN.

In development, public assets of supported types are compressed on the fly with the enabled gzip and/or brotli encodings instead.

```ts
export default defineConfig({
  compressPublicAssets: {
    gzip: true,
    brotli: true, // enable gzip and brotli pre-compression
  },
});
```

### `serverAssets`

Assets can be accessed in server logic and bundled in production.

```ts
export default defineConfig({
  serverAssets: [
    {
      baseName: "templates",
      dir: "./templates", // bundle templates/ as server assets
    },
  ],
});
```

:read-more{to="/docs/assets#server-assets"}
