Cross-origin module scripts require CORS response headers (#tilPost)

While reading Jake Archibald’s article How to win at CORS, I learned that classic and module scripts treat CORS (Cross-Origin Resource Sharing) differently.
<!– Not a CORS request –>
<script src=”https://example.com/script.j…


This content originally appeared on Stefan Judis Web Development and was authored by Stefan Judis

While reading Jake Archibald's article How to win at CORS, I learned that classic and module scripts treat CORS (Cross-Origin Resource Sharing) differently.

<!-- Not a CORS request -->
<script src="https://example.com/script.js"></script>
<!-- CORS request -->
<script type="module" src="https://example.com/script.js"></script>

If you're requesting a JavaScript file in a module context the response needs to define an Access-Control-Allow-Origin header or it will be blocked by the browser.

Classic scripts don't require it to not break the web and guarantee backward compatibility. Very interesting! If you want to learn more, read the article. It's a good one.


Reply to Stefan


This content originally appeared on Stefan Judis Web Development and was authored by Stefan Judis


Print Share Comment Cite Upload Translate Updates
APA

Stefan Judis | Sciencx (2021-10-16T22:00:00+00:00) Cross-origin module scripts require CORS response headers (#tilPost). Retrieved from https://www.scien.cx/2021/10/16/cross-origin-module-scripts-require-cors-response-headers-tilpost/

MLA
" » Cross-origin module scripts require CORS response headers (#tilPost)." Stefan Judis | Sciencx - Saturday October 16, 2021, https://www.scien.cx/2021/10/16/cross-origin-module-scripts-require-cors-response-headers-tilpost/
HARVARD
Stefan Judis | Sciencx Saturday October 16, 2021 » Cross-origin module scripts require CORS response headers (#tilPost)., viewed ,<https://www.scien.cx/2021/10/16/cross-origin-module-scripts-require-cors-response-headers-tilpost/>
VANCOUVER
Stefan Judis | Sciencx - » Cross-origin module scripts require CORS response headers (#tilPost). [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/10/16/cross-origin-module-scripts-require-cors-response-headers-tilpost/
CHICAGO
" » Cross-origin module scripts require CORS response headers (#tilPost)." Stefan Judis | Sciencx - Accessed . https://www.scien.cx/2021/10/16/cross-origin-module-scripts-require-cors-response-headers-tilpost/
IEEE
" » Cross-origin module scripts require CORS response headers (#tilPost)." Stefan Judis | Sciencx [Online]. Available: https://www.scien.cx/2021/10/16/cross-origin-module-scripts-require-cors-response-headers-tilpost/. [Accessed: ]
rf:citation
» Cross-origin module scripts require CORS response headers (#tilPost) | Stefan Judis | Sciencx | https://www.scien.cx/2021/10/16/cross-origin-module-scripts-require-cors-response-headers-tilpost/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.