cdn
A bare ky client for Salla's public CDN at cdn.salla.network; it sends no store, language or customer headers.
import { cdn } from '@salla.sa/twilight-theme-engine/api/client';In plain words
Some Salla files are the same for every store and live on a public CDN (a network of servers that hands out files quickly), such as the shared translations. cdn.get('js/translations.json') downloads from https://cdn.salla.network/.
Unlike api, it adds nothing to the request: no store, no language, no token.
Signature
const cdn: KyInstance
// ky.extend({ prefix: 'https://cdn.salla.network', timeout: 5000 }) no hooks, no extra headersExample
import { cdn } from '@salla.sa/twilight-theme-engine/api/client';
/** How large the shared translations file is, for a debug panel. */
export async function translationsSize(): Promise<number> {
const text = await cdn.get('js/translations.json').text();
return text.length;
}
How it behaves
Its only use inside the engine is
translations.get().Errors throw
HTTPErrorlike any ky call;translations.getis the one caller that catches them.
Gotchas
It is not an image helper and has nothing to do with
cdn.assets.salla.network. For theme assets and resized images useuseAsset()from the hooks.
Related
The HTTP client behind every engine API module: ky, pointed at the Salla Store API, adding store, language, version, token and branch headers.
translationsDownloads Salla's shared translations file, every storefront message in Arabic and English, which the engine's translate function reads.
useAssetBuilds URLs for your theme's own asset files and for Salla's asset CDN, optionally asking the CDN to resize an image.
Source and docs
- Engine source:
packages/theme-engine/src/api/client.ts