Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid Partial Content HTTP download in webR, fixing browser caching for cairo.so #151

Merged
merged 1 commit into from
Jul 14, 2024

Conversation

georgestagg
Copy link
Collaborator

Github Pages supports serving content with HTTP status 206, "Partial Content", but content that is served in this way is not cached by the brower (at least, not by Chrome). So, when using Shinylive hosted on GitHub Pages multiple (slow!) network requests are sent on every page load for the webR resource file cairo.so, even if the file has already been previously downloaded by the browser.

Emscripten is configured to fetch lazy filesystem content with size greater than 1MB in chunks, using the partial content mechanism. The chunk size is hard coded here and I can't see a way to disable things. We might be able to submit a PR to Emscripten implementing such a disable switch, but even so this would then still require upgrading Emscripten for a new release of webR, which we can't do until R 4.5.0 for ABI reasons.

For the moment, this PR patches the lazy file system mechanism to always skip partial content and download the entire file. With this, cairo.so is loaded in a single request, and the response is cached as expected.

R package library content should not be affected, since webR uses a custom VFS mounting routine for those in any case. Also, the patch only touches webR, pyodide should not be affected in any way. AFAICT, the only file large enough in webR's base distribution to be affected in this way will be cairo.so itself.

@georgestagg georgestagg requested a review from schloerke July 13, 2024 20:05
@wch
Copy link
Collaborator

wch commented Jul 13, 2024

Just curious: how will this affect the shinylive.io site, or other hosting services?

@georgestagg
Copy link
Collaborator Author

It will depend on the hosting service, specifically on if the response to a HTTP HEAD request for content is served with the Accept-Ranges: bytes header set. When set, Emscripten will try to download lazy-loaded content in chunks (the check is here). We're modifying the conditional on hasByteServing so that the code behaves as if Accept-Ranges is never set.

For the shinylive.io site in particular, it does not serve cairo.so with Accept-Ranges right now so there should be no change in behaviour. A quick online search suggests the feature is possible to enable in S3, but is off by default.

@georgestagg georgestagg merged commit a2c0958 into posit-dev:main Jul 14, 2024
2 checks passed
@georgestagg georgestagg deleted the avoid-partial-content branch July 14, 2024 09:24
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