mirror of
https://github.com/hensm/fx_cast.git
synced 2026-06-12 18:39:58 +00:00
Load framework API script earlier to speed up cast init
This commit is contained in:
@@ -17,7 +17,7 @@ if (!_window.chrome) {
|
|||||||
_window.chrome.cast = cast;
|
_window.chrome.cast = cast;
|
||||||
|
|
||||||
let bridgeInfo: any;
|
let bridgeInfo: any;
|
||||||
let isFramework = false;
|
let frameworkScriptPromise: Promise<HTMLScriptElement>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If loaded within a page via a <script> element,
|
* If loaded within a page via a <script> element,
|
||||||
@@ -35,11 +35,11 @@ if (document.currentScript) {
|
|||||||
_window.cast = {};
|
_window.cast = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// Queue up the framework script load to speed up init
|
||||||
* Set isFramework flag to load framework once the base cast API is
|
frameworkScriptPromise = loadScript(CAST_FRAMEWORK_SCRIPT_URL);
|
||||||
* initialized
|
frameworkScriptPromise.catch(() => {
|
||||||
*/
|
logger.error("Failed to load CAF script!");
|
||||||
isFramework = true;
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -48,13 +48,9 @@ onMessage(async message => {
|
|||||||
case "cast:initialized": {
|
case "cast:initialized": {
|
||||||
bridgeInfo = message.data;
|
bridgeInfo = message.data;
|
||||||
|
|
||||||
// If framework API is requested, load that first
|
// If framework API is requested, ensure loaded
|
||||||
if (isFramework) {
|
if (frameworkScriptPromise) {
|
||||||
try {
|
await frameworkScriptPromise;
|
||||||
await loadScript(CAST_FRAMEWORK_SCRIPT_URL);
|
|
||||||
} catch (err) {
|
|
||||||
logger.error("Failed to load CAF script!");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Call page script/framework API script's init function
|
// Call page script/framework API script's init function
|
||||||
|
|||||||
Reference in New Issue
Block a user