Static Files
The runtime serves the files of public/ itself, before building the Application: stylesheets, JavaScript, images, fonts, favicon.ico, robots.txt, and what AssetMapper or Webpack Encore compile there.
Such an Invocation pays no Kernel boot, and is answered even when the Application fails to build (ADR 0009).
A file is served when:
- the request is a
GETor aHEAD; - the path names a regular file under
<project_dir>/public, a symbolic link leading out of it excluded; - no segment of the path starts with a dot (
..,.env,.htaccess), but for a leading/.well-known/; - its extension is not
.php.
Every other request goes to the Application, directories included: there is no index file nor directory listing.
[!IMPORTANT]
A file wins over a route of the same path.
An application answering/robots.txtfrom a controller while shippingpublic/robots.txtgets the file: delete the file to keep the route.
Responses
- The
Content-Typecomes from the extension,application/octet-streamfor an unknown one, without charset. - Each response carries
X-Content-Type-Options: nosniff, and anETagof the bytes it sends: a matchingIf-None-Matchgets a304without body. Cache-Controlispublic, max-age=0, must-revalidate: browsers keep the file but check it on each use.- It is
public, max-age=31536000, immutablefor a file whose name changes with its content: one that amanifest.jsonin its directory, or in one above, maps from another name.
AssetMapper'spublic/assets/manifest.jsonand Webpack Encore'spublic/build/manifest.json(with versioning) are such manifests.
Names alone are not trusted, asfont-awesome.csswould look as digested asapp-mH7q4W_.css. Rangerequests get the whole file with a200.
No CDN stands in front of a function: every request for a Static File is an Invocation, billed and possibly paying a cold start.
Long-lived caching of digested files is what spares most of them.
Compression
A file is sent compressed when the client accepts it, in this order:
- a precompressed variant shipped next to it,
app.css.br, thenapp.css.zst, thenapp.css.gz, written by any build step; - otherwise, when the
static_compressionruntime option is set, the file compressed by the runtime.
{
"extra": {
"runtime": {
"static_compression": "gzip"
}
}
}
static_compression is false by default, "gzip", "zstd" or "br", each needing its extension (zlib, zstd, brotli): any other value, or one whose extension is not loaded, answers every Invocation with a 500 until fixed.
The Scaleway php85 runtime loads zlib and zstd but not brotli: use "zstd" or "gzip" there, and ship .br variants built beforehand for brotli.
The runtime only compresses textual files (text/*, JavaScript, JSON, XML, SVG, WebAssembly) of at least 1 KiB, and keeps the results in memory for the Warm Process, up to 32 MiB.
The order of preference is the runtime's: only a q=0 in Accept-Encoding refuses an encoding.
Compressed responses carry Content-Encoding, an ETag of their own and Vary: Accept-Encoding.
A request for app.css.gz itself gets that file, as any other.
Limits
- A Static File must fit in one Function Response, base64-encoded when it is binary, which takes a third more.
Scaleway enforces no limit, but responses of 10 MiB and more intermittently fail with a504after 60 seconds (measured).
The runtime therefore refuses Static Files over 6 MiB in a Function Response: it answers a 500 and logs the file, andscaleway-packagewarns about such files. - A file written at runtime under
public/, such as an upload, is only served by the instance that wrote it, each instance having its own disk. - Store uploads, large files and busy sites' assets on Object Storage, behind Edge Services or not, and point
framework.assets.base_urlsto it. assets:installboots the Kernel: at deploy time, run it from apost-install-cmdwith an explicit env,@php bin/console assets:install public --env=prod, for the same reasons ascache:warmup.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
|