fileserver_add explained: how FiveM downloads your resources
What the fileserver_add convar does, how the pattern and URL work, and the mistakes that break resource downloads.
Every player who joins your server has to download your resources first. Maps, vehicles, clothing, scripts. By default all of that comes straight from your server, over the same port players connect to. The fileserver_add convar lets you change where those downloads come from.
What happens when a player joins
When a player connects, the server sends a list of every resource and every file inside it, together with a hash of each file. The client compares that list with its local cache. Files it already has with a matching hash are skipped. Anything missing or changed is downloaded over HTTP.
Without fileserver_add, those HTTP requests go to your server itself, at a path like /files/resource/file. Your FXServer process answers every one of them, while also running the game.
The syntax
fileserver_add ".*" "https://cdn.example.com/files"It takes two arguments. The first is a pattern that is matched against resource names. The second is the base URL the client should download those resources from.
The pattern is a regular expression. ".*" matches every resource, which is what you want in almost every case. You could send only some resources elsewhere, for example "^cars_" for a vehicle pack, but splitting things up rarely helps and makes problems harder to trace.
The URL must not end with a slash. https://cdn.example.com/files/ breaks downloads. https://cdn.example.com/files works.
One URL per resource, and no fallback
This is the part that catches people out. The server picks the download URL for each resource once, when it builds the list it sends to the client. The client then uses that one URL. If the host behind it is down, the client retries the same address a few times and then stops with a "Failure downloading" error. It does not fall back to your server.
So whatever you put behind fileserver_add has to be at least as reliable as your server. Pointing it at a home connection or a cheap box that goes offline now and then will cost you joins.
Common mistakes
- A trailing slash at the end of the URL.
- Pointing it at a plain file host. The URL has to serve exactly the files and paths your server would serve, so in practice it is a proxy or CDN that pulls from your server.
- Using it with a cache but without adhesive_cdnKey. Without a fixed key the files are different for every player, so nothing can be reused. We explain why in a separate post.
- Forgetting to restart. The convar is read at startup, so it only takes effect after a restart.
How FiveMCDN uses it
FiveMCDN gives you two lines for your server.cfg. One is a fileserver_add line that points at your own CDN endpoint, the other sets adhesive_cdnKey. The first time a file is requested, we pull it from your server once. After that it is served from Cloudflare's edge, close to the player, and your server never sees those requests.
# fivemcdn.com: add these 2 lines to server.cfg, then restart your server
fileserver_add ".*" "https://cache.fivemcdn.com/t/ab12cd34/files"
set adhesive_cdnKey "k9f2Qv7pXn3wLtB8sZ1aRcYd"The quickstart takes about five minutes, and the Free plan does not need a card.