Static files
The public folder, cache headers, compression, ranges, MERGE(), TOUCH() and their configuration.
On this page
API
type
public/
The folder of static files.
public/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.
public/
css/default.css
js/app.js
img/logo.png
favicon.ico
manifest.webmanifest
type
/_<plugin>/<path>
URLs that read static files from a plugin.
/_<plugin>/<path>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.
<link rel="stylesheet" href="/_shop/css/shop.css" />
type
*.min.js, *-min.css, *@min.js
Files that are sent without minification.
*.min.js, *-min.css, *@min.jsA .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.
/js/jquery.min.js
/css/bootstrap-min.css
/js/spa@min.js
type
Expires, Cache-Control, Last-Modified, ETag
HTTP cache headers of static files.
Expires, Cache-Control, Last-Modified, ETagStatic 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.
Cache-Control: public, must-revalidate, max-age=60
Last-Modified: Mon, 02 Nov 2026 10:00:00 GMT
ETag: 858100
type
Content-Encoding: gzip
Gzip compression of static files.
Content-Encoding: gzipWith 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.
type
Range: bytes=<start>-<end>
Partial responses for large files.
Range: bytes=<start>-<end>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.
GET /video/intro.mp4
Range: bytes=0-
type
application/manifest+json
Web app manifest files.
application/manifest+jsonwebmanifest is in the default CONF.$httpfiles, so public/manifest.webmanifest is served with the content type application/manifest+json.
<link rel="manifest" href="/manifest.webmanifest" />
method
$.resume()
Sends the static file of the request the normal way.
$.resume()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.
ROUTE('FILE /docs/*.pdf', function($) {
if ($.query.key === CONF.docskey)
$.resume();
else
$.fallback(401);
});
method
$.notmodified(date)
Answers 304 when the browser already has this version.
$.notmodified(date)| Parameter | Type | Description |
|---|---|---|
date |
String |
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.
ROUTE('GET /feed/', function($) {
var date = MAIN.feeddate.toUTCString();
if ($.notmodified(date))
return;
$.httpcache(date);
$.plain(MAIN.feed);
});
method
$.httpcache(date)
Adds the static cache headers to the response.
$.httpcache(date)| Parameter | Type | Description |
|---|---|---|
date |
Date|String |
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.
$.httpcache(new Date(2026, 0, 1));
$.plain('Hello');
method
TOUCH([url])
Clears the cached state of static files.
TOUCH([url])| Parameter | Type | Description |
|---|---|---|
url? |
String |
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.
Total.Fs.writeFile(PATH.public('css/theme.css'), css, function() {
TOUCH('/css/theme.css');
});
method
MERGE(url, file1, [file2], [...])
Creates a virtual file made of several files.
MERGE(url, file1, [file2], [...])| Parameter | Type | Description |
|---|---|---|
url |
String |
The URL of the merged file, for example /css/all.css. |
files |
String|Array |
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.
exports.install = function() {
MERGE('/css/all.css', 'bootstrap.min.css + default.css');
MERGE('/js/all.js', '/js/app.js + /js/forms.js');
};
method
LOCALIZE(fn)
Sets the delegate that picks the language of a request.
LOCALIZE(fn)| Parameter | Type | Description |
|---|---|---|
fn |
Function |
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.
LOCALIZE(function($) {
return ($.headers['accept-language'] || 'en').substring(0, 2);
});
method
PATH.public([path])
Returns the path of a file in the public folder.
PATH.public([path])| Parameter | Type | Description |
|---|---|---|
path? |
String |
Relative path. |
Returns String Absolute path.
Joins path to the public/ folder (or CONF.$dirpublic). Without path, it returns the folder.
Total.Fs.writeFile(PATH.public('robots.txt'), 'User-agent: *', NOOP);
config
$dirpublic
Folder of static files.
$dirpublicReturns String
An absolute path to use instead of public/ in the app folder.
Default: '' (public/).
$dirpublic : /www/static
config
$httpfiles
Extensions served as static files.
$httpfilesReturns 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.
$httpfiles : avif, glb
config
$httpcompress
Gzip compression of responses.
$httpcompressReturns Boolean
When on, text static files and text responses are compressed for clients that accept gzip.
Default: true.
$httpcompress : false
config
$httpmaxage
The max-age of static files, in seconds.
$httpmaxageReturns Number
Used in Cache-Control: public, must-revalidate, max-age=<value>. After this time the browser asks again and usually gets 304.
Default: 60.
$httpmaxage : 300
config
CONF.$httpexpire
The Expires header of static files.
CONF.$httpexpireReturns 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.
config
$httpetag
Suffix of the ETag header.
$httpetagReturns 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).
$httpetag : build42
config
$httprangebuffer
Maximum size of an open range, in kB.
$httprangebufferReturns Number
For a Range header without an end, this many kB are sent.
Default: 5120.
$httprangebuffer : 10240
config
$minifyjs
Minifies JavaScript files.
$minifyjsReturns Boolean
Minifies static .js files, files sent with $.file() and merged files. Files with .min, -min or @min are not minified.
Default: true.
$minifyjs : false
config
$minifycss
Minifies CSS files.
$minifycssReturns Boolean
Minifies static .css files, files sent with $.file() and merged files.
Default: true.
$minifycss : false
config
$minifyhtml
Minifies HTML.
$minifyhtmlReturns Boolean
Minifies static .html files and HTML responses.
Default: true.
$minifyhtml : false
config
$root
Root path of the app.
$rootReturns 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.
Default: ''.
$root : /app/
config
$httpcacheoffset
since 0.0.16
Moves the Last-Modified date of static files.
$httpcacheoffsetReturns String
A time such as 1 minute added to the file date in the Last-Modified header of static files. See Configuration.
Default: ''.
$httpcacheoffset : 1 minute