Guide · Production Operations

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 ModelInfrastructure NeededTypical LatencyMonthly CostBest For
1. Static Storage / CDNS3, Cloudflare R2, GCS, or GitHub Pages40–150 ms warm~$0–$2/moCheckout forms, MapLibre maps, store locators, client-side CSV
2. Edge API (Cloudflare Workers)Worker + R2 bucket binding15–60 ms~$5/moZero-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/moHigh-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#

bash
# 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.txg

Required Bucket CORS & Cache Headers#

Browsers need Range in AllowedHeaders and Content-Range, Content-Length, Accept-Ranges in ExposeHeaders:

json
[
  {
    "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:

  1. In-flight deduplication: Concurrent queries requesting the same byte range share a single network fetch.
  2. In-memory LRU (24 MB): Works everywhere, including Safari Private Mode and Node.js.
  3. 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:

ts
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):

ts
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 ScopeMin RAMDisk (raw / compressed)Recommended Machine
Single state / metro (us_ca, gb_lon)256 MB0.2–1.0 GBAny laptop or $4 VPS
Continent (us or eu)2 GB25–35 GB4 vCPU NVMe VPS
Full planet (128 regions)4 GB (16 GB rec.)66.5 GB / 23.1 GB8 vCPU / 16 GB NVMe
Full planet + buildings, parcels, GeoIP & TZ (--with-all)4 GB (16 GB rec.)291 GB / 86.4 GB8 vCPU / 16–32 GB NVMe

Running with Docker or systemd#

bash
docker run -d \
  --name texspace \
  -p 4000:4000 \
  -v texspace_data:/data \
  -e TEXSPACE_PULL_PRESET=us_ca \
  ghcr.io/nside/texspace:latest

Zero-Downtime Monthly Upgrades & Live OSM Updates#

bash
# 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 texspace

Passing --osm-sync minute (or hour / day) continuously streams official OpenStreetMap updates and hot-reloads active readers with zero dropped requests.


4. Troubleshooting#

SymptomLikely CauseFix
Browser TypeError: Failed to fetch on a custom bucketMissing Range CORS headerAdd Range to AllowedHeaders and Content-Range to ExposeHeaders in your bucket CORS settings.
HTTP Range ... returned short bodyStatic host ignores Range: or re-compresses .txg with gzipServe .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 bootCall geo.prefetch(lat, lon) on page mount, or enable geoip="auto" on <texspace-address-input>.
<texspace-address-input> isn't autofilling sibling fieldsInputs outside <form> or missing tokensPlace inputs in the same <form> and add standard autocomplete="address-level2" or data-texspace="city".