This error is because textures used by WebGL must either be served from the same domain (origin) as the main page or they must be served with the correct cross-origin headers.
For the server: if your assets are served from a different domain you must ensure they have the correct CORS headers.
For the game/client there are two options.
First: If you set the ASSET_PREFIX config in the index.html to a URL, then all assets will be loaded from this prefix. If the ASSET_PREFIX is an absolute URL (for example, starting with βhttps://β) then we enable cross-origin loading on the textures.
Second: You can manually enable cross origin texture loading with this code:
var handler = this.app.loader.getHandler("texture");
handler.crossOrigin = "anonymous";
You must run this code before any textures are requested.
To run the code before any textures are requested, I just need to create a script including this code in the initialize function and set this script to the first in SCRIPT LOADING ORDER ?
Hello, dave. I have another question. As you can see, I just modified the index.html :
In order to using the CDN, I need to separate the index.html and other files. So I must change the URLs in index.html and config.json. And every time I publish the game, I need to modify them manually.
Is there any way to change the URLs ? According to you :
If you can I would not change any URLs for assets, scenes or config data. These can all updated using the ASSET_PREFIX. The only URLs you should need to change are the script tags in the index.html.