CORS headers for `widgets.js`

oembed

#1

Hi, we’re using the Twitter for Websites JavaScript API, and are trying to import dynamically https://platform.twitter.com/widgets.js. The problem is that dynamic imports require CORS:

Access to script at ‘https://platform.twitter.com/widgets.js’ from origin ‘http://localhost:1234’ has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.

Can Twitter please set the appropriate headers? Thanks!


#2

Hello @CryptoClimate,

Can you please provide the code & browser/version you’re using to try to dynamically import widgets.js so we can look into this further?

Thanks!


#3

I’m using Chromium 71 (Firefox doesn’t support dynamic imports) and the code is simply

import('https://platform.twitter.com/widgets.js').then(() => console.log('import worked'));

Here’s a jsbin showing dynamic import working for jQuery and failing for the widget.js.


#4

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.