Skip to content

Commit cfb8dce

Browse files
authored
Merge branch 'master' into perf/stabilize-infinite-playback-engine
2 parents 2d5c134 + 83c5c8d commit cfb8dce

40 files changed

+7256
-987
lines changed

CONTRIBUTING.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ is a community-driven project, and every meaningful contribution helps
66
improve the platform for learners and educators around the world.
77

88
If you’re new to the project, start by setting up the local
9-
development environment using the guide linked above, then explore
9+
development environment using the guide linked below, then explore
1010
open issues or discussions to find a place to contribute.
1111

1212
- [How to set up a local server](README.md#how-to-set-up-a-local-server)
@@ -49,9 +49,13 @@ following resources:
4949
- [JavaScript tutorial - w3schools.com](https://www.w3schools.com/js/default.asp)
5050
- [JavaScript reference - MDN Web Docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript)
5151

52-
Programmers, please follow these general [guidelines for
52+
For code contributions, please follow these general [guidelines for
5353
contributions](https://github.com/sugarlabs/sugar-docs/blob/master/src/contributing.md).
5454

55+
### AI guidelines
56+
57+
Follow [AI guidelines for Sugar Labs](https://github.com/sugarlabs/sugar-docs/blob/master/src/contributing.md#ai-guidelines-for-sugar-labs)
58+
5559
### Before You Push
5660

5761
Run these commands locally before submitting a PR:

Docs/PRODUCTION_BUILD_STRATEGY.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Production Build Optimization Strategy: Architecture & Performance
2+
3+
## Why
4+
Music Blocks currently serves mostly unbundled, raw JavaScript and asset files.
5+
While this works in development, it introduces limitations for:
6+
- Production performance (high HTTP request count)
7+
- Predictable offline caching
8+
- Service worker reliability
9+
- Long-term maintainability alongside AMD-based loading
10+
11+
This document explores a **lightweight investigation** of production build optimizations without introducing a full migration or breaking existing architecture.
12+
13+
## Current Behavior
14+
- JavaScript and assets are largely served as individual files.
15+
- No formal production bundling or minification strategy exists.
16+
- Service worker caching must account for many independent assets (hundreds of individual JS files).
17+
- RequireJS / AMD loading is the primary module system, which constrains conventional bundling approaches that expect ES modules or CommonJS.
18+
19+
## Analysis: Current State & Offline Impact
20+
21+
### Baseline Metrics (as of Feb 2026)
22+
To provide a comparison reference for future optimizations:
23+
- **Total JavaScript Request Count:** ~248 files (209 Application, 39 Libraries).
24+
- **Total JavaScript Size (Uncompressed):** ~12.94 MB.
25+
- **Application Logic (`js/`):** 209 files, 6.42 MB.
26+
- **Libraries (`lib/`):** 39 files, 6.52 MB.
27+
- **Loading Model:** Sequential AMD loading, resulting in a deep waterfall of requests.
28+
29+
### Service Worker & Offline Caching
30+
The current `sw.js` implementation follows a **stale-while-revalidate** pattern with significant constraints for offline reliability:
31+
1. **Limited Pre-caching:** Only `index.html` is explicitly pre-cached. All other assets are cached dynamically upon first request.
32+
2. **Fragmentation:** Caching 200+ individual JS files increases the risk of partial cache states (where some files are cached and others are not), leading to runtime errors in offline mode.
33+
3. **Implicit Dependencies:** If the service worker fails to intercept a single AMD dependency (e.g., due to a network blip), the entire module fails to load.
34+
4. **Cache Invalidation:** Without content hashing, ensuring users receive the latest version of a file depends on the browser's fetch behavior and the SW's revalidation logic, which can be inconsistent.
35+
36+
### Proposed Strategy (Groundwork)
37+
This strategy focuses on low-risk, future-oriented thinking:
38+
39+
### 1. Selective Minification
40+
Before full bundling, we can investigate minifying individual files during a "build" step.
41+
- Reduces payload size without changing the loading model.
42+
- Keep source maps for easier production debugging.
43+
44+
### 2. Asset Grouping (Low-Risk Experiment)
45+
Instead of bundling everything into one file (which breaks RequireJS's dynamic loading), we can group "core" modules that are always loaded together.
46+
- Example: `js/utils/utils.js`, `js/turtles.js`, and basic library wrappers.
47+
48+
### 3. Hashing/Versioning
49+
Introduce a simple hashing mechanism for production assets to ensure service workers can reliably identify when an asset has changed.
50+
51+
### Running the Asset Analysis Script
52+
53+
From the repository root:
54+
55+
```bash
56+
node scripts/analyze-production-assets.js
57+
```
58+
59+
This script recursively scans the `js/` and `lib/` directories to report:
60+
- Total JavaScript file count
61+
- Aggregate size
62+
- Estimated minification savings
63+
64+
No build step or configuration is required.
65+
66+
## Scope & Constraints
67+
- **Documentation first:** This document serves as the primary outcome of this phase.
68+
- **No replacement of RequireJS / AMD:** The current module system is deeply integrated and stable.
69+
- **No build system overhaul:** Use existing Node.js scripts or lightweight tools if any implementation is attempted.
70+
- **No runtime behavior changes:** The priority is stability.
71+
72+
## Next Steps / Roadmap
73+
- [x] Audit total request count and asset sizes.
74+
- [ ] Implement a lightweight minification pass for `js/` files in the `dist/` task.
75+
- [ ] Research RequireJS `r.js` optimizer or modern alternatives (like Vite or esbuild) that can target AMD.
76+
- [ ] Create a manifest for the Service Worker to enable reliable pre-caching of core assets.

css/activities.css

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,15 @@
1414

1515
@import url("play-only-mode.css");
1616

17-
*:focus {
17+
*:focus:not(:focus-visible) {
1818
outline: none;
1919
}
2020

21+
*:focus-visible {
22+
outline: 2px solid #0066FF !important;
23+
outline-offset: 2px;
24+
}
25+
2126
body:not(.dark) #helpfulSearch,
2227
body:not(.dark) .ui-autocomplete {
2328
background-color: #fff !important;
@@ -509,6 +514,8 @@ div.back:active {
509514
position: absolute;
510515
top: 0;
511516
left: 0;
517+
518+
height: calc(var(--vh, 1vh) * 100);
512519
}
513520

514521
.canvasHolder.hide {
@@ -623,7 +630,7 @@ nav ul li {
623630

624631
#planet-iframe {
625632
width: 100vw;
626-
height: 100vh;
633+
height: calc(var(--vh, 1vh) * 100);
627634
background-color: #fff;
628635
position: absolute;
629636
top: 0;
@@ -633,6 +640,8 @@ nav ul li {
633640
iframe,
634641
canvas {
635642
overflow: clip !important;
643+
width: 100%;
644+
height: 100%;
636645
}
637646

638647
.projectname {
@@ -1199,7 +1208,7 @@ table {
11991208
left: 0 !important;
12001209
border: 0 !important;
12011210
overflow-x: hidden;
1202-
overflow-y: auto;
1211+
overflow: visible;
12031212
width: calc(100% - 130px) !important;
12041213
max-width: 350px;
12051214
padding: 1rem 1rem 0 1rem;
@@ -1209,6 +1218,10 @@ table {
12091218
align-items: center;
12101219
}
12111220

1221+
#helpScrollWrapper {
1222+
overflow-y: auto;
1223+
}
1224+
12121225
#helpBodyDiv .heading,
12131226
#helpBodyDiv .description,
12141227
#helpBodyDiv .message {

0 commit comments

Comments
 (0)