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

fix: loading of underscore and other text assets over CDN #586

Conversation

navinkarkera
Copy link
Member

Backport of openedx#33124

The text plugin for requirejs is used to load text assets such as .underscore files. To avoid CORS issues when loading such assets from a different domain, such as a when a CDN is in use, this plugin loads such assets as .js files by adding a script tag.

What this means in practice is that if you configure the platform to serve static assets from a CDN, it will try to load file.underscore.js instead of file.underscore. We can override this behaviour by providing a useXhr function for the text plugin configuration. The plugin will use this function to determine whether to use XHR or the script tag approach.

In this change we are asking it to always use XHR since the concerns about CORS raised by the plugins documentation don't apply here.

ref: https://github.com/requirejs/text/blob/3f9d4c19b3a1a3c6f35650c5788cbea1db93197a/README.md#xhr-restrictions

The text plugin for requirejs is used to load text assets such as .underscore files.
To avoid CORS issues when loading such assets from a different domain, such as a when
a CDN is in use, this plugin loads such assets as .js files by adding a script tag.

What this means in practice is that if you configure the platform to serve static
assets from a CDN, it will try to load `file.underscore.js` instead of
`file.underscore`. We can override this behaviour by providing a `useXhr` function
for the text plugin configuration. The plugin will use this function to determine
whether to use XHR or the script tag approach.

In this change we are asking it to always use XHR since the concerns about CORS
raised by the plugins documentation don't apply here.

ref: https://github.com/requirejs/text/blob/3f9d4c19b3a1a3c6f35650c5788cbea1db93197a/README.md#xhr-restrictions
@navinkarkera navinkarkera self-assigned this Sep 14, 2023
@navinkarkera navinkarkera merged commit 0362a0f into opencraft-release/palm.1 Sep 14, 2023
41 checks passed
@navinkarkera navinkarkera deleted the navin/palm-backport/fix-loading-from-cdn branch September 14, 2023 18:35
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