Commit 6e79486
feat(app): serve Pyodide from origin instead of CDN
Pyodide assets (~14MB across pyodide.js, .asm.js, .asm.wasm,
python_stdlib.zip, pyodide-lock.json) used to be loaded from
cdn.jsdelivr.net on every page load. Two problems:
1. Dev iteration: even with browser cache, cold loads were ~10s.
2. PWA tier: the SW can't cache cross-origin opaque responses
reliably, so "offline-capable" apps were never truly offline.
New behavior:
- New route /_violetear/pyodide/{filename} serves from a local disk
cache at ~/.cache/violetear/pyodide-<version>/ (override via
VIOLETEAR_PYODIDE_CACHE env var).
- Cache is populated lazily on first request from the same CDN —
no work at App() construction, no impact on tests that don't fetch
Pyodide files.
- Atomic .partial → final rename so a crashed download leaves no
half-baked file.
- The injected <script src=...> now points at the local route;
loadPyodide()'s default indexURL follows automatically.
- PWA Service Worker asset list now includes the Pyodide files so
tier 4 (pomodoro) can be fully offline after first visit.
Three new smoke tests:
- Local route serves the seeded files; whitelist-only (no path traversal).
- Injected client script uses /_violetear/pyodide/, not the CDN URL.
- SW asset list includes all five Pyodide files.
Tests stub the cache via VIOLETEAR_PYODIDE_CACHE → no real network
fetch in CI. 43 passed.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent e0b250a commit 6e79486
2 files changed
Lines changed: 172 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
227 | 227 | | |
228 | 228 | | |
229 | 229 | | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
230 | 305 | | |
231 | 306 | | |
232 | 307 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| 12 | + | |
11 | 13 | | |
12 | 14 | | |
13 | 15 | | |
| |||
16 | 18 | | |
17 | 19 | | |
18 | 20 | | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
19 | 89 | | |
20 | 90 | | |
21 | 91 | | |
| |||
320 | 390 | | |
321 | 391 | | |
322 | 392 | | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
323 | 409 | | |
324 | 410 | | |
325 | 411 | | |
| |||
714 | 800 | | |
715 | 801 | | |
716 | 802 | | |
717 | | - | |
718 | | - | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
719 | 807 | | |
720 | 808 | | |
721 | 809 | | |
| |||
786 | 874 | | |
787 | 875 | | |
788 | 876 | | |
| 877 | + | |
| 878 | + | |
| 879 | + | |
| 880 | + | |
| 881 | + | |
| 882 | + | |
| 883 | + | |
789 | 884 | | |
790 | 885 | | |
791 | 886 | | |
| |||
0 commit comments