Speed up browser phone initialization
All checks were successful
Create Release / build (push) Successful in 3s
All checks were successful
Create Release / build (push) Successful in 3s
- Add preload hint for Twilio SDK to start loading earlier - Add DNS prefetch and preconnect for Twilio servers - Check SDK immediately instead of waiting 500ms - Reduce polling interval from 100ms to 50ms Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -7445,6 +7445,11 @@ class TWP_Admin {
|
|||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
<!-- Preload and preconnect for faster loading -->
|
||||||
|
<link rel="preload" href="https://unpkg.com/@twilio/voice-sdk@2.11.0/dist/twilio.min.js" as="script">
|
||||||
|
<link rel="dns-prefetch" href="//unpkg.com">
|
||||||
|
<link rel="dns-prefetch" href="//chunderw-vpc-gll.twilio.com">
|
||||||
|
<link rel="preconnect" href="https://chunderw-vpc-gll.twilio.com" crossorigin>
|
||||||
<!-- Twilio Voice SDK v2 from unpkg CDN -->
|
<!-- Twilio Voice SDK v2 from unpkg CDN -->
|
||||||
<script src="https://unpkg.com/@twilio/voice-sdk@2.11.0/dist/twilio.min.js"></script>
|
<script src="https://unpkg.com/@twilio/voice-sdk@2.11.0/dist/twilio.min.js"></script>
|
||||||
<script>
|
<script>
|
||||||
@@ -8235,7 +8240,7 @@ class TWP_Admin {
|
|||||||
// Check if SDK loaded and initialize
|
// Check if SDK loaded and initialize
|
||||||
// Poll for Twilio SDK availability (window.load may not fire on mobile)
|
// Poll for Twilio SDK availability (window.load may not fire on mobile)
|
||||||
var sdkCheckAttempts = 0;
|
var sdkCheckAttempts = 0;
|
||||||
var maxSdkCheckAttempts = 50; // 5 seconds max
|
var maxSdkCheckAttempts = 100; // 5 seconds max (100 * 50ms)
|
||||||
|
|
||||||
function checkAndInitialize() {
|
function checkAndInitialize() {
|
||||||
sdkCheckAttempts++;
|
sdkCheckAttempts++;
|
||||||
@@ -8244,16 +8249,23 @@ class TWP_Admin {
|
|||||||
console.log('Twilio SDK loaded successfully');
|
console.log('Twilio SDK loaded successfully');
|
||||||
initializeBrowserPhone();
|
initializeBrowserPhone();
|
||||||
} else if (sdkCheckAttempts < maxSdkCheckAttempts) {
|
} else if (sdkCheckAttempts < maxSdkCheckAttempts) {
|
||||||
// Keep checking every 100ms
|
// Keep checking every 50ms for faster response
|
||||||
setTimeout(checkAndInitialize, 100);
|
setTimeout(checkAndInitialize, 50);
|
||||||
} else {
|
} else {
|
||||||
showError('Twilio Voice SDK failed to load. Please check your internet connection and try refreshing the page.');
|
showError('Twilio Voice SDK failed to load. Please check your internet connection and try refreshing the page.');
|
||||||
console.error('Twilio SDK not found after ' + sdkCheckAttempts + ' attempts.');
|
console.error('Twilio SDK not found after ' + sdkCheckAttempts + ' attempts.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start checking after a brief delay
|
// Check immediately - SDK script is synchronous so should be loaded
|
||||||
setTimeout(checkAndInitialize, 500);
|
// If not ready yet (mobile), polling will catch it
|
||||||
|
if (typeof Twilio !== 'undefined' && Twilio.Device) {
|
||||||
|
console.log('Twilio SDK already loaded');
|
||||||
|
initializeBrowserPhone();
|
||||||
|
} else {
|
||||||
|
// Start polling immediately
|
||||||
|
checkAndInitialize();
|
||||||
|
}
|
||||||
|
|
||||||
// Also keep the window.load as backup for desktop
|
// Also keep the window.load as backup for desktop
|
||||||
$(window).on('load', function() {
|
$(window).on('load', function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user