Enable Cross-Origin Resource Sharing (CORS) for Phaser.js

當你用 Phaser JS 載入不同網域的資源、素材時,就會遇到瀏覽器同源政策的阻擋,並冒出一堆錯誤訊息,例如:

XMLHttpRequest cannot load http://s.ntustcoding.club/scroll-game-workshop/map.json. No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘http://s.codepen.io’ is therefore not allowed access.

實際上,Phaser 本身是有支援 跨來源資源共享 CORS 的,只要透過一行簡單的語法就可以解決囉,當然前提是你所使用的網路空間也有支援 CORS 才行。 閱讀全文 Enable Cross-Origin Resource Sharing (CORS) for Phaser.js