---
title: Static files
project: Total.js V5
version: 0.0.20
section: reference
language: en
license: MIT
url: https://totaljs.es/docs/total-js-v5/0-0-20/reference/static-files/
updated: 2026-11-18T16:57:14.575Z
---

# Static files

> The public folder, cache headers, compression, ranges, MERGE(), TOUCH() and their configuration.

## API

### public/

Type: `type`

The folder of static files.

A request whose URL has an extension is served from `public/`: `/img/logo.png` is `public/img/logo.png`. The folder can be changed with `CONF.$dirpublic`. Only extensions listed in `CONF.$httpfiles` are served. File requests with `POST`, `PUT`, `PATCH` or `DELETE` are closed; `HEAD` returns the headers only.

Example: Structure
```text
public/
	css/default.css
	js/app.js
	img/logo.png
	favicon.ico
	manifest.webmanifest
```

### /_<plugin>/<path>

Type: `type`

URLs that read static files from a plugin.

A file URL that starts with `/_` and a plugin name reads from the `public/` folder of that plugin: `/_shop/css/shop.css` is `plugins/shop/public/css/shop.css`. The files get the same minification and caching as files of the app.

Example: Link a plugin file
```html
<link rel="stylesheet" href="/_shop/css/shop.css" />
```

### *.min.js, *-min.css, *@min.js

Type: `type`

Files that are sent without minification.

A `.js`, `.css` or `.html` file whose path contains `.min`, `-min` or `@min` is streamed as it is. Other files of these types are minified when the matching `$minify*` option is on.

Example: Sent unchanged
```text
/js/jquery.min.js
/css/bootstrap-min.css
/js/spa@min.js
```

### Expires, Cache-Control, Last-Modified, ETag

Type: `type`

HTTP cache headers of static files.

Static files get `Expires` (`CONF.$httpexpire`, one year ahead), `Cache-Control: public, must-revalidate, max-age=<CONF.$httpmaxage>`, `Last-Modified` with the file date and `ETag: 858<CONF.$httpetag>`. When the browser sends the same `If-Modified-Since` date, the answer is `304 Not Modified`.

`.zip` and `.rar` files, and `.js`, `.css` and `.html` files in debug mode, are sent with `Cache-Control: private, no-cache, no-store, max-age=0`.

Example: Response headers
```text
Cache-Control: public, must-revalidate, max-age=60
Last-Modified: Mon, 02 Nov 2026 10:00:00 GMT
ETag: 858100
```

### Content-Encoding: gzip

Type: `type`

Gzip compression of static files.

With `CONF.$httpcompress` on and `Accept-Encoding: gzip` in the request, text files are compressed: `text/plain`, JavaScript, `text/css`, `text/jsx`, `text/html`, JSON, XML, `image/svg+xml`, Markdown and notebook files. Text types are sent with `charset=utf-8`. Other types are not compressed.

### Range: bytes=<start>-<end>

Type: `type`

Partial responses for large files.

A request with a `Range` header gets `206 Partial Content` with `Content-Range`. When the range has no end, at most `CONF.$httprangebuffer` kB are sent. Players use this to stream video and audio. A range that starts after the end of the file closes the connection; an end after the end of the file is cut to the last byte.

Example: Request
```text
GET /video/intro.mp4
Range: bytes=0-
```

### application/manifest+json

Type: `type`

Web app manifest files.

`webmanifest` is in the default `CONF.$httpfiles`, so `public/manifest.webmanifest` is served with the content type `application/manifest+json`.

Example: Link the manifest
```html
<link rel="manifest" href="/manifest.webmanifest" />
```

### $.resume()

Type: `method`

Sends the static file of the request the normal way.

In a `FILE` route, `$.resume()` hands the request back to static file handling: the matching file from `public/` (or from a plugin) is sent with minification, caching and compression.

Example: Check before sending
```js
ROUTE('FILE /docs/*.pdf', function($) {
	if ($.query.key === CONF.docskey)
		$.resume();
	else
		$.fallback(401);
});
```

### $.notmodified(date)

Type: `method`

Answers 304 when the browser already has this version.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `date` | `String` | yes |  | A UTC date string, the same value you send in `Last-Modified`. |

Returns: `Boolean` `true` when the 304 response was sent.

Compares `date` with the `If-Modified-Since` header. When they are equal, it sends `304 Not Modified` with the cache headers and returns `true`; otherwise it returns `undefined` and you send the response.

Example: Cache a generated file
```js
ROUTE('GET /feed/', function($) {
	var date = MAIN.feeddate.toUTCString();
	if ($.notmodified(date))
		return;
	$.httpcache(date);
	$.plain(MAIN.feed);
});
```

### $.httpcache(date)

Type: `method`

Adds the static cache headers to the response.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `date` | `Date|String` | yes |  | The date of the content. |

Sets `Expires` and `Cache-Control` (unless already set), `Last-Modified` to `date` and `ETag`, the same headers static files get. Use it with `$.notmodified()` for generated content.

Example: Generated content
```js
$.httpcache(new Date(2026, 0, 1));
$.plain('Hello');
```

### TOUCH([url])

Type: `method`

Clears the cached state of static files.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `url` | `String` | no |  | URL of the file, for example `/css/default.css`. |

Removes the stored minified file, the stored date and size and the not-found mark of one URL, or of all static files when `url` is missing. The next request reads the file again. Use the URL as the browser requests it, with the case of the file name and with `CONF.$root` when it is set. Static HTML translated by `LOCALIZE()` is cached per language, so for it call `TOUCH()` without an argument.

Example: After writing a file
```js
Total.Fs.writeFile(PATH.public('css/theme.css'), css, function() {
	TOUCH('/css/theme.css');
});
```

### MERGE(url, file1, [file2], [...])

Type: `method`

Creates a virtual file made of several files.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `url` | `String` | yes |  | The URL of the merged file, for example `/css/all.css`. |
| `files` | `String|Array` | yes |  | Files to merge, as more arguments. |

Returns: `String` The URL of the merged file.

Registers `url` as a file built from the listed files and returns the URL. Each file argument is a string (several names joined with `+`) or an array of absolute file paths or URLs, used as they are. In a string, a name without a slash is taken from `public/js/` for `.js` and `public/css/` otherwise; a path with `/` is relative to `public/`; `~` starts an absolute path; `http://` and `https://` are downloaded. Each local file is minified by its type setting unless its name marks it as minified; downloaded files are added as they are. In release mode the result is built once and saved to `tmp/`; in debug mode it is built on every request. With `CONF.$root`, the returned URL contains the root.

Example: CSS and JS bundles
```js
exports.install = function() {
	MERGE('/css/all.css', 'bootstrap.min.css + default.css');
	MERGE('/js/all.js', '/js/app.js + /js/forms.js');
};
```

### LOCALIZE(fn)

Type: `method`

Sets the delegate that picks the language of a request.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `fn` | `Function` | yes |  | `function($)` that returns the language. |

`fn($)` returns a language code. It is called for routes, sockets and static `.html` files; static HTML is translated into that language and cached per language. The full topic is in [Localization](../../guides/localization/).

Example: Language from the header
```js
LOCALIZE(function($) {
	return ($.headers['accept-language'] || 'en').substring(0, 2);
});
```

### PATH.public([path])

Type: `method`

Returns the path of a file in the public folder.

| Parameter | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `path` | `String` | no |  | Relative path. |

Returns: `String` Absolute path.

Joins `path` to the `public/` folder (or `CONF.$dirpublic`). Without `path`, it returns the folder.

Example: Write a public file
```js
Total.Fs.writeFile(PATH.public('robots.txt'), 'User-agent: *', NOOP);
```

### $dirpublic

Type: `config`

Folder of static files.

Returns: `String`

An absolute path to use instead of `public/` in the app folder.

Default: `'' (public/)`.

Example: Config file
```text
$dirpublic : /www/static
```

### $httpfiles

Type: `config`

Extensions served as static files.

Returns: `Object`

In the config file, list extensions separated by commas; they are added to the default list, which contains among others `jpg`, `png`, `gif`, `webp`, `svg`, `ico`, `js`, `mjs`, `css`, `html`, `json`, `txt`, `xml`, `md`, `map`, `woff`, `woff2`, `ttf`, `pdf`, `zip`, `mp3`, `mp4`, `webm`, `wasm` and `webmanifest`.

Default: `a list of common web types`.

Example: Config file
```text
$httpfiles : avif, glb
```

### $httpcompress

Type: `config`

Gzip compression of responses.

Returns: `Boolean`

When on, text static files and text responses are compressed for clients that accept gzip.

Default: `true`.

Example: Config file
```text
$httpcompress : false
```

### $httpmaxage

Type: `config`

The max-age of static files, in seconds.

Returns: `Number`

Used in `Cache-Control: public, must-revalidate, max-age=<value>`. After this time the browser asks again and usually gets 304.

Default: `60`.

Example: Config file
```text
$httpmaxage : 300
```

### CONF.$httpexpire

Type: `config`

The Expires header of static files.

Returns: `String`

A UTC date one year ahead. Total.js sets it at start and refreshes it every hour; do not set it in the config file.

### $httpetag

Type: `config`

Suffix of the ETag header.

Returns: `String`

The ETag of static files is `858` + this value. When it is empty, the app `version` without dots and spaces is used, so a new version changes the ETag.

Default: `'' (from version)`.

Example: Config file
```text
$httpetag : build42
```

### $httprangebuffer

Type: `config`

Maximum size of an open range, in kB.

Returns: `Number`

For a `Range` header without an end, this many kB are sent.

Default: `5120`.

Example: Config file
```text
$httprangebuffer : 10240
```

### $minifyjs

Type: `config`

Minifies JavaScript files.

Returns: `Boolean`

Minifies static `.js` files, files sent with `$.file()` and merged files. Files with `.min`, `-min` or `@min` are not minified.

Default: `true`.

Example: Config file
```text
$minifyjs : false
```

### $minifycss

Type: `config`

Minifies CSS files.

Returns: `Boolean`

Minifies static `.css` files, files sent with `$.file()` and merged files.

Default: `true`.

Example: Config file
```text
$minifycss : false
```

### $minifyhtml

Type: `config`

Minifies HTML.

Returns: `Boolean`

Minifies static `.html` files and HTML responses.

Default: `true`.

Example: Config file
```text
$minifyhtml : false
```

### $root

Type: `config`

Root path of the app.

Returns: `String`

When the app runs under a path, for example `/app/`, the root is removed from static URLs before the file is looked up, and `MERGE()` returns URLs with the root. Details in [Configuration](../../guides/configuration/).

Default: `''`.

Example: Config file
```text
$root : /app/
```

### $httpcacheoffset

Type: `config` · Since: `0.0.16`

Moves the Last-Modified date of static files.

Returns: `String`

A time such as `1 minute` added to the file date in the `Last-Modified` header of static files. See [Configuration](../../guides/configuration/).

Default: `''`.

Example: Config file
```text
$httpcacheoffset : 1 minute
```
