Skip to content

Replace Firefox 5s delay with readiness-based initialization#5337

Merged
walterbender merged 2 commits intosugarlabs:masterfrom
Ashutoshx7:fix/firefox-loading-delay
Feb 7, 2026
Merged

Replace Firefox 5s delay with readiness-based initialization#5337
walterbender merged 2 commits intosugarlabs:masterfrom
Ashutoshx7:fix/firefox-loading-delay

Conversation

@Ashutoshx7
Copy link
Contributor

@Ashutoshx7 Ashutoshx7 commented Jan 26, 2026

Performance Improvement

This PR replaces the arbitrary 5-second loading delay for Firefox with a smart, readiness-based initialization check.

Context

Since 2015, Music Blocks has had a hardcoded setTimeout(..., 5000) for Firefox browsers to work around historical hardware acceleration and loading issues. This forced all Firefox users to wait 5 seconds, even on fast modern machines.

Changes

  1. Added waitForReadiness() in js/utils/utils.js:

    • Polls for critical dependencies (createjs, Howler, jQuery) and DOM readiness (canvas, loader, toolbars).
    • Uses a configurable polling interval (100ms) with a minimum wait (500ms) for stability.
    • Includes a safe fallback timeout (10s) to ensure the app always loads eventually.
  2. Updated js/activity.js:

    • Replaced the 5-second setTimeout with waitForReadiness.

Results

Browser Before After Improvement
Firefox (Fast) 5000ms ~500ms ~90% Faster 🚀
Firefox (Slow) 5000ms (risky) Up to 10s More Reliability
Chromium No delay No delay Unchanged

Verification

  • Tested locally on Firefox-based browser (Zen).
  • Confirmed initialization happens in ~502ms instead of 5000ms.

@github-actions
Copy link
Contributor

✅ All Jest tests passed! This PR is ready to merge.

@Ashutoshx7 Ashutoshx7 force-pushed the fix/firefox-loading-delay branch from a878043 to b2bbdc6 Compare January 26, 2026 03:45
@github-actions
Copy link
Contributor

✅ All Jest tests passed! This PR is ready to merge.

Instead of an arbitrary 5-second setTimeout for Firefox, this change
introduces a waitForReadiness() function that polls for actual
dependency readiness before initializing the app.

The new approach:
- Polls every animation frame for critical dependencies (createjs, Howler, jQuery)
- Checks for required DOM elements (canvas, loader, toolbars)
- Initializes as soon as ready (minimum 500ms for stability)
- Falls back to initialization after maximum 10s timeout
- Logs actual initialization time for debugging

Benefits:
- Fast Firefox machines: ~500-800ms instead of 5000ms
- Slow Firefox machines: waits appropriately up to 10s
- Provides insight via console logging
- Future-proof: adapts to actual dependencies

This addresses technical debt from 2015 when the arbitrary delay
was introduced as a workaround for Firefox hardware acceleration issues.
@Ashutoshx7 Ashutoshx7 force-pushed the fix/firefox-loading-delay branch from b2bbdc6 to 9048a4f Compare January 31, 2026 20:39
@github-actions
Copy link
Contributor

✅ All Jest tests passed! This PR is ready to merge.

@github-actions
Copy link
Contributor

github-actions bot commented Feb 3, 2026

✅ All Jest tests passed! This PR is ready to merge.

@Ashutoshx7
Copy link
Contributor Author

@walterbender this is followup pr for firefox browser
#5319

@walterbender
Copy link
Member

very nice

@walterbender walterbender merged commit d537e40 into sugarlabs:master Feb 7, 2026
6 checks passed
@Ashutoshx7 Ashutoshx7 deleted the fix/firefox-loading-delay branch February 7, 2026 14:57
vanshika2720 pushed a commit to vanshika2720/musicblocks that referenced this pull request Feb 11, 2026
…ugarlabs#5337)

Instead of an arbitrary 5-second setTimeout for Firefox, this change
introduces a waitForReadiness() function that polls for actual
dependency readiness before initializing the app.

The new approach:
- Polls every animation frame for critical dependencies (createjs, Howler, jQuery)
- Checks for required DOM elements (canvas, loader, toolbars)
- Initializes as soon as ready (minimum 500ms for stability)
- Falls back to initialization after maximum 10s timeout
- Logs actual initialization time for debugging

Benefits:
- Fast Firefox machines: ~500-800ms instead of 5000ms
- Slow Firefox machines: waits appropriately up to 10s
- Provides insight via console logging
- Future-proof: adapts to actual dependencies

This addresses technical debt from 2015 when the arbitrary delay
was introduced as a workaround for Firefox hardware acceleration issues.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants