A manager to ease resolving, downloading and executing additional code from async chunks or any arbitrary JavaScript files.
resolveRemoteChunk
function.resolveRemoteChunk
function by setting forceRemoteChunkResolution: true
in ChunkManager.configure(...)
.This API is only useful if you are working with any form of Code Splitting.
Example of using this API with async chunks:
• new ChunkManager()
▸ Static
configure(config
): void
Configures ChunkManager
to be able to resolve location of additional
chunks (or arbitrary code) in production.
Optionally, it also allows to set up caching to avoid over-fetching of chunks.
Name | Type | Description |
---|---|---|
config |
ChunkManagerConfig |
Configuration options. |
void
▸ Static
invalidateChunks(chunksIds?
): Promise
<void
>
Clears the cache (if configured in ChunkManager.configure) and removes downloaded files for given chunks from the filesystem.
This function can be awaited to detect if the chunks were invalidated and for error handling.
Name | Type | Default value | Description |
---|---|---|---|
chunksIds |
string [] |
[] |
Array of chunk Ids to clear from cache and remove from filesystem. |
Promise
<void
>
▸ Static
loadChunk(chunkId
, parentChunkId?
): Promise
<void
>
Resolves given chunk's location, download and execute it. Once the returned Promise is resolved, the code should have been evaluated.
The execution of the code is handled internally by threading in React Native.
Name | Type | Description |
---|---|---|
chunkId |
string |
Id of the chunk. |
parentChunkId? |
string |
Id of the parent chunk. |
Promise
<void
>
▸ Static
preloadChunk(chunkId
): Promise
<void
>
Resolves given chunk's location and download it without executing.
This function can be awaited to detect if the chunk was downloaded and for error handling.
Name | Type | Description |
---|---|---|
chunkId |
string |
Id of the chunk. |
Promise
<void
>
▸ Static
resolveChunk(chunkId
, parentChunkId?
): Promise
<ChunkConfig
>
Resolves a URL to a given chunks and whether to download a chunk or reuse previously downloaded one.
Name | Type | Description |
---|---|---|
chunkId |
string |
Id of the chunk. |
parentChunkId? |
string |
- |
Promise
<ChunkConfig
>
Promise with chunk's URL as url
and a boolean fetch
whether to download a chunk
or reuse previously downloaded one.