External CDN Resource Usage
Version Requirements
- Base library version
>=2.26.0 @ray-js/rayversion>=1.6.10- Developer tools version
>=0.8.4 - Cannot be used together with the Tuya CDN feature
Feature Description
To reduce the mini app package size, Ray provides an external CDN resource feature. You can upload static resources (images, audio, etc.) to a CDN. At runtime, local resource paths are automatically replaced with the corresponding CDN URLs for the current region.
Uploading to a CDN
You must choose and configure your own CDN provider and upload the resources in advance. Common providers include:
Configure the CDN
Add a cdn directory (example under src) and create a cdnImage.json file. Example structure:
cdnImage.json must specify the CDN URL for each region code. Region codes to configure:
- AY: China
- AZ: United States
- EU: Europe (fallback)
- IN: India
- UE: U.S. East
- WE: Western Europe
- RU: Russia
Notes:
- CDN URLs in the configuration must match the actually uploaded resource URLs, otherwise replacement fails.
- The Europe (EU) region acts as the fallback when a URL for another region is missing.
Usage in the Project
Ray provides the getCdnUrl method. Image paths are automatically replaced with region-specific CDN URLs.