Load resources from external web site

Load resources from external web site
0.0 0


Hello. I’m using cocos2d js for developing game and distribute it on mobile platforms (iOS/Android)
Is it possible somehow to get resources from external URLs being in runtime?
I mean this:
cc.audioEngine.playEffect("http://mywebsite.com/res/audio/sound.wav", false);
I know, this may look pointless and weird, but I really need it)
Would be appreciated for any workaround as well.

How to change the default preloader image in cocos2d-JS 3.0 RC2


you’ll need to do something about cross origin resource sharing.

an easy solution is using http://cors.io/


adding this will allow you to load data from external sites.



is it critical for native apps too? (i mean cors)
the thing is that I tried to run the code above, I also tried to preload sounds via AudioEngine feature, but I can’t see the app is accessing web resources. I own the server, i have an access to web logs.

At the moment my goal is to understand whether it’s technically possible at all?


OK, I’ve finally invented a workaround. Maybe it will be useful for someone, I’m gonna keep it here.


I also need the ability to load audio from URLs (like in Unity). Calling cc.loader.loadRes with a URL isn’t enough – it does not work. Of course, I’d strongly prefer to not use an unsupported workaround for such critical functionality for our app.

Any idea if this is on the roadmap? @slackmoehrle ? Thanks! :slight_smile:


Bump, we actually will need this within the next few weeks. Is this feature (load audio from web URL instead of file path) on your roadmap?



I was shocked to learn this can’t be done. We need the ability to load other external asset types from external sources (scenes, prefabs, animations) not just audio. @slackmoehrle, could you please comment if this is on the roadmap? Feels like really basic functionality to me.


Sure. Let me find out.