Hosting, Caching & Self-Hosting
You can start shipping immediately against the free public CDN (https://shards.texspace.dev/txg/v2) with zero infrastructure to manage. When you need full data ownership, private VPC isolation, custom territories, or sub-2ms backend API latency, choose the hosting model that fits your team:
| Deployment Model | Infrastructure Needed | Typical Latency | Monthly Cost | Best For |
|---|---|---|---|---|
| 1. Static Storage / CDN | S3, Cloudflare R2, GCS, or GitHub Pages | 40–150 ms warm | ~$0–$2/mo | Checkout forms, MapLibre maps, store locators, client-side CSV |
| 2. Edge API (Cloudflare Workers) | Worker + R2 bucket binding | 15–60 ms | ~$5/mo | Zero-egress global REST geocoding API at the edge |
3. Self-Hosted Server (texspace serve) | Single NVMe VPS (4–16 GB RAM) | 1–24 ms p50 | ~$10–$35/mo | High-throughput /v1/batch, offline GeoIP, AI MCP agents, strict VPCs |
1. Self-Hosting Static Files (S3, Cloudflare R2, GCS, Caddy)#
All serverless data — the global planet archive, IANA timezones, custom territory layers (pack-layer), and private store catalogs (pack-overlay) — is just immutable static files served over standard HTTP Range requests.
Packing Your Own Files#
# Convert downloaded SQLite shards into static HTTP-Range files
texspace pack-txg --from data/global --out data/txg_v2 --jobs 8
texspace pack-tz-txg --from data/global/tz.db --out data/txg_v2/tz.txg
# Pack custom territory boundaries and private store catalogs
texspace pack-layer -i zones.geojson --name delivery_zones -o data/txg_v2/layers/delivery_zones.txg
texspace pack-overlay -i stores.csv --name stores -o data/txg_v2/overlays/stores.txgRequired Bucket CORS & Cache Headers#
Browsers need Range in AllowedHeaders and Content-Range, Content-Length, Accept-Ranges in ExposeHeaders:
[
{
"AllowedOrigins": ["*"],
"AllowedMethods": ["GET", "HEAD"],
"AllowedHeaders": ["Range", "If-None-Match", "If-Modified-Since"],
"ExposeHeaders": ["Content-Range", "Content-Length", "Accept-Ranges", "ETag"],
"MaxAgeSeconds": 86400
}
]Upload all .txg files with Content-Type: application/octet-stream and Cache-Control: public, max-age=31536000, immutable (do not gzip-encode .txg files in transit — they are already block-compressed internally).
Built-In Client Caching & Pre-Warming#
By default (cache: "auto"), Texspace.open() caches downloaded byte ranges automatically using three layers:
- In-flight deduplication: Concurrent queries requesting the same byte range share a single network fetch.
- In-memory LRU (24 MB): Works everywhere, including Safari Private Mode and Node.js.
- Browser / Worker Cache API (
caches.open("texspace-txg-v2")): Survives page reloads so returning visitors skip cold boot entirely.
Call geo.prefetch(lat, lon) on page load (or geo.warm(...) during idle time) so the first user keystroke responds immediately:
await geo.prefetch(37.7749, -122.4194);
// Non-blocking background pre-warmer (yields to active user input, respects Save-Data)
geo.warm(["10 Downing Street, London, SW1A 2AA", { type: "timezone", lat: 37.7749, lon: -122.4194 }], {
delayMs: 40,
});2. Cloudflare Workers (Zero-Egress R2 Binding)#
Bind your R2 bucket directly so range reads never leave Cloudflare's network ($0 egress):
import { Texspace, r2BucketTransport } from "texspace";
import wasmModule from "texspace/wasm/texspace_wasm_bg.wasm";
let cachedGeo: Promise<Texspace> | null = null;
function getGeo(env: Env) {
if (!cachedGeo) {
cachedGeo = Texspace.open("https://shards.texspace.dev/txg/v2", {
wasm: wasmModule,
transport: r2BucketTransport(env.TXG_BUCKET, "txg/v2"),
cache: false,
});
}
return cachedGeo;
}
export default {
async fetch(request: Request, env: Env): Promise<Response> {
const url = new URL(request.url);
const geo = await getGeo(env);
if (url.pathname === "/v1/search") {
return Response.json(await geo.search(url.searchParams.get("text") || "", { limit: 5 }));
}
if (url.pathname === "/v1/enrich") {
return Response.json(
await geo.enrich(Number(url.searchParams.get("lat")), Number(url.searchParams.get("lon")), {
reverse: true,
timezone: true,
layers: ["layers/us_states.txg", "layers/world_countries.txg"],
})
);
}
return new Response("Not Found", { status: 404 });
},
};See examples/cloudflare-worker/ for a complete Wrangler project.
3. Dedicated Self-Hosted Server (texspace serve)#
Hardware Sizing#
| Coverage Scope | Min RAM | Disk (raw / compressed) | Recommended Machine |
|---|---|---|---|
Single state / metro (us_ca, gb_lon) | 256 MB | 0.2–1.0 GB | Any laptop or $4 VPS |
Continent (us or eu) | 2 GB | 25–35 GB | 4 vCPU NVMe VPS |
| Full planet (128 regions) | 4 GB (16 GB rec.) | 66.5 GB / 23.1 GB | 8 vCPU / 16 GB NVMe |
Full planet + buildings, parcels, GeoIP & TZ (--with-all) | 4 GB (16 GB rec.) | 291 GB / 86.4 GB | 8 vCPU / 16–32 GB NVMe |
Running with Docker or systemd#
docker run -d \
--name texspace \
-p 4000:4000 \
-v texspace_data:/data \
-e TEXSPACE_PULL_PRESET=us_ca \
ghcr.io/nside/texspace:latest[Unit]
Description=texspace Geocoding API
After=network-online.target
[Service]
Type=simple
ExecStart=/usr/local/bin/texspace serve --db /var/lib/texspace --host 127.0.0.1 --port 4000 --osm-sync minute
ExecReload=/bin/kill -HUP $MAINPID
Restart=on-failure
RestartSec=3
LimitNOFILE=65535
[Install]
WantedBy=multi-user.targetZero-Downtime Monthly Upgrades & Live OSM Updates#
# Preview and apply incremental SHA-256 upgrades without downtime
texspace update --db /var/lib/texspace --check
texspace update --db /var/lib/texspace --prune-delta
systemctl reload texspacePassing --osm-sync minute (or hour / day) continuously streams official OpenStreetMap updates and hot-reloads active readers with zero dropped requests.
4. Troubleshooting#
| Symptom | Likely Cause | Fix |
|---|---|---|
Browser TypeError: Failed to fetch on a custom bucket | Missing Range CORS header | Add Range to AllowedHeaders and Content-Range to ExposeHeaders in your bucket CORS settings. |
HTTP Range ... returned short body | Static host ignores Range: or re-compresses .txg with gzip | Serve .txg as raw application/octet-stream with Accept-Ranges: bytes and no gzip Content-Encoding. |
| First browser query feels slow (300–500 ms) | Cold router + region boot | Call geo.prefetch(lat, lon) on page mount, or enable geoip="auto" on <texspace-address-input>. |
<texspace-address-input> isn't autofilling sibling fields | Inputs outside <form> or missing tokens | Place inputs in the same <form> and add standard autocomplete="address-level2" or data-texspace="city". |