Skip to content

Load the Media Library widget script from the CDN again - #1378

Open
gabrielcld2 wants to merge 2 commits into
developfrom
feature/WPP-1232-cdn-media-library-script
Open

gabrielcld2 wants to merge 2 commits into
developfrom
feature/WPP-1232-cdn-media-library-script

Conversation

@gabrielcld2

Copy link
Copy Markdown
Collaborator

Follow-up to #1254 and the 3.3.7 hotfix.

Approach

  • In 3.3.7, the Media Library widget script was served from a copy bundled in the plugin. WP 7.1 adds crossorigin="anonymous" to cross-origin scripts on block editor screens for Chromium 137+, and the CDN didn't send CORS headers, so the script was blocked.
  • media-library.cloudinary.com now returns Access-Control-Allow-Origin: * for its .js files in production.
  • Media::editor_assets() loads the script from CLOUDINARY_ENDPOINTS_MEDIA_LIBRARY again, so the plugin picks up widget updates without anyone copying files by hand.
  • Removes the bundled js/cloudinary-media-library.js, which nothing else uses. It was identical to the CDN version apart from the header comment.

QA notes

  • Check the header: curl -sI -H "Origin: https://example.com" https://media-library.cloudinary.com/global/all.js | grep -i access-control returns access-control-allow-origin: *.
  • On WordPress 7.1 with Chrome/Chromium 137 or later:
    • Open a new post in the block editor and add an Image block.
    • Click Media Library, then the Cloudinary tab.
    • In DevTools, all.js loads from media-library.cloudinary.com with crossorigin="anonymous", there are no CORS errors in the console, and the widget renders.
  • Check that the Cloudinary DAM admin page still loads the widget.
  • Before this change, the same steps on WP 7.1 failed with blocked by CORS policy: No 'Access-Control-Allow-Origin' header.

The CDN now sends Access-Control-Allow-Origin, so the plugin loads the
script from media-library.cloudinary.com again and the vendored copy is
no longer used.

@utkarshcloudinary utkarshcloudinary left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

looks good ✅

This branch has not been deployed

No deployments
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.

3 participants