Function: prefixedCdnBaseAsync()
ts
function prefixedCdnBaseAsync(publicKey, cdnBase?): Promise<string>;Defined in: cdn-base/prefixed.ts:44
Your project's prefixed CDN base: <prefix>.ucarecd.net, computed with WebCrypto. A browser API — and the one to prefer there, since it adds ~0.3 kB to a bundle against ~1 kB for prefixedCdnBase, which has to carry a SHA-256 of its own to be able to return without awaiting.
On Node it resolves to the same string, hashing with node:crypto's WebCrypto, so isomorphic code can await it on the server too. There prefixedCdnBase is just as small and needs no await.
Being async, it cannot be inlined into a base(...) call — resolve it once at startup and keep the string.
Parameters
| Parameter | Type | Default value | Description |
|---|---|---|---|
publicKey | string | undefined | The project's public key. |
cdnBase? | string | PREFIX_CDN_BASE | The zone to prefix; defaults to PREFIX_CDN_BASE. Pass one explicitly only if you deliver from a different prefixed zone. |
Returns
Promise<string>
The prefixed base, without a trailing slash.
Example
ts
const myCdn = cdn.base(await prefixedCdnBaseAsync('demopublickey'))
myCdn.file(uuid).href
// https://1s4oyld5dc.ucarecd.net/:uuid/