Skip to content

Use CORS-clean hosts for in-browser data reads - #54

Merged
mmcky merged 1 commit into
mainfrom
fix/wasm-cors-urls
Aug 6, 2026
Merged

mmcky merged 1 commit into
mainfrom
fix/wasm-cors-urls

Conversation

@mmcky

@mmcky mmcky commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

This site executes code cells in the reader's browser (Pyodide via pyodide_http.patch_all()), so every pandas URL read is subject to CORS on each redirect hop. The github.com/<org>/<repo>/raw/… form is a 302 whose response carries an empty access-control-allow-origin header, which browsers reject before following the redirect — so those reads fail in the one repo where the browser is the runtime. raw.githubusercontent.com and (for LFS files) media.githubusercontent.com serve access-control-allow-origin: * and work. The regression and the accompanying repoint rule are tracked in QuantEcon/data-lectures#46.

Five reads flipped, two groups:

Lecture Read Old host New host
long_run_growth mpd2020.xlsx github.com/QuantEcon/data-lectures/raw/… (from #52) raw.githubusercontent.com
inflation_history longprices.xls, chapter_3.xlsx github.com/QuantEcon/data-lectures/raw/… (from #53) raw.githubusercontent.com
inequality SCF_plus_mini.csv github.com/QuantEcon/high_dim_data/raw/… (pre-existing) media.githubusercontent.com (LFS)
mle SCF_plus_mini_no_weights.csv github.com/QuantEcon/high_dim_data/raw/… (pre-existing) media.githubusercontent.com (LFS)

The {download} link and prose links keep the github.com form — they are plain navigations, CORS does not apply, and that form gives the reader the friendlier GitHub UI on click.

Verification: all five new URLs fetched from this site's own origin (quantecon.github.io) in headless Chromium — 200 with the exact expected sizes (1,765,204 / 388,608 / 73,281 / 32,853,734 / 75,902,999 bytes; the first three byte-identical to the sha256-verified data-lectures copies). The old form fails the same test with Failed to fetch. Reproduce from any quantecon.github.io page console: fetch('https://github.com/QuantEcon/data-lectures/raw/main/lectures/mpd2020.xlsx') rejects; the raw.githubusercontent.com equivalent resolves.

The data-lectures audit classifies references by org/repo across all GitHub URL forms, so these stay pattern data-lectures/unchanged — the strict migration-consistency check is unaffected.

🤖 Generated with Claude Code

This site executes code cells in the reader's browser (Pyodide via
pyodide_http), so every pandas URL read is subject to CORS on each
redirect hop. The github.com/<org>/<repo>/raw/ form 302s with an empty
access-control-allow-origin header and fails in the browser before the
redirect is followed; raw.githubusercontent.com and (for LFS files)
media.githubusercontent.com serve access-control-allow-origin: * and
work.

Flips the five affected reads:
- long_run_growth.md, inflation_history.md: the data-lectures reads
  repointed in #52/#53 move to raw.githubusercontent.com
- inequality.md, mle.md: the pre-existing SCF reads move to
  media.githubusercontent.com (the LFS host heavy_tails already uses)

{download} links and prose links are plain navigations, so they keep
the github.com form. All five new URLs verified fetching from this
site's origin in headless Chromium with the exact expected byte counts.
The regression and the repoint rule are tracked in
QuantEcon/data-lectures#46.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Copilot AI lite review requested due to automatic review settings August 6, 2026 08:49
@netlify

netlify Bot commented Aug 6, 2026

Copy link
Copy Markdown

Deploy Preview for beautiful-dodol-cb9543 failed.

Name Link
🔨 Latest commit b8acd44
🔍 Latest deploy log https://app.netlify.com/projects/beautiful-dodol-cb9543/deploys/6a744a858ce6440009ce2120

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates a handful of in-lecture, in-browser (Pyodide) pandas data reads to use CORS-friendly GitHub content hosts so fetches succeed under browser CORS rules (especially across redirects).

Changes:

  • Switched data reads in long_run_growth and inflation_history from github.com/<org>/<repo>/raw/... to raw.githubusercontent.com/... to avoid redirect/CORS failures.
  • Switched LFS-backed CSV reads in inequality and mle from github.com/<org>/<repo>/raw/... to media.githubusercontent.com/... to ensure the browser receives file bytes (not a blocked redirect or LFS pointer path).

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
lectures/mle.md Repoints SCF CSV read to media.githubusercontent.com for CORS-clean in-browser fetch.
lectures/long_run_growth.md Repoints Maddison XLSX read to raw.githubusercontent.com to avoid CORS/redirect issues.
lectures/inflation_history.md Repoints two Excel reads to raw.githubusercontent.com to keep browser fetches CORS-clean.
lectures/inequality.md Repoints SCF CSV read to media.githubusercontent.com for CORS-clean in-browser fetch.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown

📖 Netlify Preview Ready!

Preview URL: https://pr-54--beautiful-dodol-cb9543.netlify.app (b8acd44)

✨ Browse the preview at the URL above.

@mmcky
mmcky merged commit d32a75d into main Aug 6, 2026
2 of 6 checks passed
@mmcky
mmcky deleted the fix/wasm-cors-urls branch August 6, 2026 08:52
mmcky added a commit to QuantEcon/data-lectures that referenced this pull request Aug 6, 2026
lecture-wasm executes cells in the reader's browser, where CORS applies
to every redirect hop; the github.com/*/raw/ form 302s with an empty
access-control-allow-origin header and fails there, while
raw.githubusercontent.com and media.githubusercontent.com (LFS) serve
ACAO * and work. The set 1/2 wasm repoints normalised wasm URLs to the
one form its runtime cannot fetch — found by the #45 validation,
tracked in #46, fixed in QuantEcon/lecture-wasm#54.

Also records the Phase 4 consequence: data.quantecon.org must serve
ACAO * before lecture-wasm can cut over (#37).

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
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