CDN and Asset Delivery
Relevant source files
The following files were used as context for generating this wiki page:
HXLoLi delivers static assets through a specialized CDN acceleration layer powered by hx-cdn-forge. This system distributes files across multiple GitHub repositories to bypass storage limits and optimize load times using parallel fetching strategies. The architecture supports global and regional delivery via jsDelivr mirrors and Cloudflare Workers.
Multi-Repository Architecture
The project splits assets into three distinct repositories to manage data volume and deployment stability. This separation ensures that large media files do not bloat the main website repository.
| Repository | Content Type | Reference Strategy | Purpose |
|---|---|---|---|
| HXLoLi | Blog static assets | Branch Reference (main) | Main website hosting. |
| HXLoLi-ANiMe | Anime data and images | Tag Reference | Versioned anime metadata. |
| HXLoLi-Music | Music, ASS lyrics, fonts | Tag Reference | High-bandwidth media delivery. |
Sources: src/utils/cdn/linkJsDelivr.ts:5-10, blog/2026/04/14/01_博客更新日志.md:55-60
Node Selection and Speed Testing
The ForgeEngine manages CDN node selection to ensure low latency. It uses a "Main Engine" to conduct speed tests and synchronizes the results across all other engine instances.
Initialization Flow
- Check Persistence: The engine looks for a saved node ID in
localStorageunder the keyhxloli-cdn-node. - Speed Test: If no node is saved, the
mainEngineperforms a speed test on available nodes (e.g.,jsd-mirror,cf-worker). - Synchronization: The engine selects the fastest node and propagates this choice to all other engines (Anime, Music, Commit).
- Cross-Tab Sync: A
storageevent listener updates active tabs if the user changes the node in another window.
The diagram shows the logic for selecting and persisting the fastest CDN node.
Sources: src/utils/cdn/linkJsDelivr.ts:46-135
Asset Delivery Strategies
HXLoLi employs different strategies based on file type and metadata availability. These strategies are encapsulated in the reqByCDNAuto function.
Music and Media Strategy
For large files like audio or complex ASS subtitle files, the system chooses the most efficient parallel download method:
- Pre-compressed (.gz): Downloads
.gzchunks in parallel via Range headers and decompresses them usingDecompressionStream. This is the optimal strategy. - Pre-sliced (info.yaml): Downloads predefined file segments in parallel.
- Binary Range: Performs multi-node segmented parallel downloads for raw binary files.
- Direct: Standard CDN download for small text files.
This diagram illustrates the parallel fetching logic for media assets.
Sources: src/utils/cdn/linkJsDelivr.ts:13-20, src/utils/cdn/linkJsDelivr.ts:182-192
Node Configuration
The system supports both global mirrors and direct Cloudflare Worker nodes for sub-repositories.
Cloudflare Workers
Sub-repositories use dedicated Cloudflare Worker domains to provide direct access, bypassing standard jsDelivr limitations:
- Anime Domain:
hxloli-anime.woa.qzz.io - Music Domain:
hxloli-music.woa.qzz.io - Payload Limit: Cloudflare Workers have a 100MB response body limit.
Sources: src/utils/cdn/linkJsDelivr.ts:65-80
Available Engines
The project exports multiple specialized engine instances:
mainEngine: Default assets using the main branch.mainCommitEngine: Versioned assets using theLATEST_COMMIT_ID.animeEngine: Anime data usingANIME_CDN_TAG.musicEngine: Music data usingMUSIC_CDN_TAG, withturboModeenabled for 3 concurrent CDN requests.
Sources: src/utils/cdn/linkJsDelivr.ts:98-120
Versioning and Tagging
To avoid CDN cache staleness (which can last up to one year), the system uses specific Git tags or commit IDs rather than the main branch for asset URLs.
- Commit IDs: Used initially for main repository assets but required extra commits to update the ID in the codebase.
- Tags: Sub-repositories (Anime/Music) use tags. A CI/CD workflow generates a new tag and submits a Pull Request to the main repository to update the version reference.
Sources: blog/2026/04/14/01_博客更新日志.md:55-70, docusaurus.config.ts:145-155
Local Development
During local development, the asset delivery system can be bypassed to use a local server:
- Local Server:
http://localhost:9527 - Detection:
isLocalDev()checks if the hostname islocalhostor127.0.0.1.
Sources: src/utils/cdn/linkJsDelivr.ts:211-224
HXLoLi's CDN layer provides a robust, parallelized delivery mechanism that handles everything from small blog images to 20MB+ ASS subtitle files by intelligently switching between specialized CDN nodes and parallel fetch strategies.