Two Markets, One Bundle: Serving GB and NI Rules From a Config Loader
Photo: Oscar Taylor , CC BY-SA 2.0, via Wikimedia Commons
The fork always starts small
It begins with one product page. Something about UKNI marking, or a delivery estimate that says 2–4 working days for GB and 3–5 working days, customs paperwork may apply for BT postcodes. So somebody branches the front end, points a second domain at it, and everyone agrees to keep them in sync.
Six months later the GB repo has had forty-one commits and the NI repo has had nine, seven of which were merge conflicts. A pricing bug fixed on GB in March is still live on NI in November. The mobile menu behaves differently because the fix went one way. Nobody is entirely sure which branch is canonical.
The border is real, but it lives in your data, not in your Git history. Treat it that way and you get one deploy, one test suite, and a much shorter list of things that can drift.
What actually differs
For a typical UK parts or goods retailer, the market deltas are narrow and enumerable:
- Availability — the odd SKU that can't be shipped to NI, or needs different labelling.
- Compliance copy — UKNI marking, warranty wording, returns routing.
- Delivery messaging — carrier, estimate, whether customs language is needed.
- Prices — usually identical in sterling, occasionally not, because of supplier terms.
- Legal strings — the address on the returns page, the entity on the invoice footer.
Notice that none of it is page structure. Nobody in Belfast wants a different checkout flow. They want the right words and the right flags.
Define the shape, then ship the shape
{
"market": "ni",
"version": "2026-11-18T09:00:00Z",
"labels": {
"deliveryEstimate": "3–5 working days",
"vatNote": "VAT included",
"returnsNote": "Returns are processed in Belfast"
},
"flags": {
"ukniMarkingRequired": true,
"customsCopy": true
},
"availability": {
"SKU-1042": "not-shippable-to-ni",
"SKU-2277": "ni-label-variant"
}
}
Small, flat, boring. Boring is the point: a config schema you can validate in CI is worth more than an elegant one you can't.
The loader
Three rules. Paint from a local default immediately, refresh from the network if you can, and never render a value you haven't validated.
import { gbDefault, niDefault } from './market-defaults.js';
const DEFAULTS = { gb: gbDefault, ni: niDefault };
const TTL = 24 * 60 * 60 * 1000;
export async function loadMarket(market) {
const cached = readCache(market);
if (cached) apply(cached); // instant, possibly stale
try {
const res = await fetchWithTimeout(`/config/market/${market}.[json](https://en.wikipedia.org/wiki/JSON)`, 1500);
if (!res.ok) throw new Error(String(res.status));
const cfg = await res.json();
if (!isValidShape(cfg)) throw new Error('bad shape');
writeCache(market, cfg);
apply(cfg);
} catch {
apply(cached || DEFAULTS[market]);
document.documentElement.dataset.config = 'degraded';
}
}
function isValidShape(cfg) {
return cfg && cfg.market && cfg.labels && cfg.flags;
}
Serve the JSON with Cache-Control: public, max-age=300, stale-while-revalidate=86400 and let your CDN edge do the work. Two files. Two cache entries. That's the whole cost of running two markets.
Cache in localStorage under a versioned key and drop it after 24 hours. Always check the shape on the way out of the cache as well as on the way in — a corrupted or truncated entry from a flaky write is more common than you'd think.
Picking the market
Don't be clever about this. A BT postcode is Northern Ireland, full stop, but a person in Newry can be sending a birthday present to Sheffield, and a person in Sheffield can be sending one to Newry. IP geolocation gets it wrong for anyone on a VPN and for half the border counties on a mobile network.
So: default to GB, offer a visible switcher in the header or footer, persist the choice in a first-party cookie, and confirm the delivery postcode at checkout — that's the only signal that actually matters for the order. The switcher should be a link with a real URL (?market=ni) so support can send someone a working link at 4:55pm on a Friday.
The kill switch
Config services go down. When yours does, two things must not happen: the page must not render undefined where a delivery estimate should be, and your front end must not hammer the endpoint from every open tab.
Ship a global flag — a tiny configEnabled value baked into the defaults, plus a localStorage override your support team can set — that stops the fetch entirely during an incident. Pair it with the degraded state above and the site keeps trading with slightly stale wording, which nobody will notice, instead of blank labels, which everybody will.
Test both sides once
- Snapshot-test the rendered page in both markets. Two snapshots, both reviewed on every PR.
- Run a contract test on the JSON schema in CI. A breaking change to the config service should fail the pipeline, not the checkout.
- Manually flip the switcher and walk five pages: product, basket, checkout, returns, footer. That's a ten-minute job that catches everything the snapshots miss.
And if you're server-rendering anyway, resolve the market there and pass the object down — no fetch needed, no flash. The loader is for the static and edge-hosted front ends where there's no server to ask at the right moment.
One codebase. Two config files. That's the border.