How to host an cocos2d-js web only game?

I’m very confused. Before I run an simple webonly cocos2d-js example, I was under the impression it generates the html5 + js files so I can host it everywhere or either run offline.

But it is not the case, to run my example locally I have to start an cocos webserver which makes me wonder: Why does it need a webserver to run offline simple html5+js code? and What Do I need to host an cocos2d-js webonly game(I use IIS)?

Because the browser does not permit to the local file operation.
(Maybe, It considers to implementation of local file is not safe) =.=

So we must build a server in the local.
Simply returns the file, do not need any other function.

To use the javascript XMLHttpRequest, this is the way that cocos get assets files (download then from internet). So instead of creating more code to handle local files they just decided to use a simple python server.

You cannot use XMLHttpRequest from local pages (the ones that you simple double click to open) as far i know.

The main reason to use XMLHttpRequest is because it is an async operation so you can play a sound create a nice load screen without pause your game ou application.

Do you want to host it locally? We use heroku and nodeJS to host our cocos games on the Internet, it works well.

1 Like

seriously?? python webserver? I have my cloud in windows using IIS, so I am not able to host it?

@edwinsoho
Yes you can, the pyhton webserver implements a simple HTTP 1.0 server, if you have any server like XAMP, ISS or any other that implements the HTTP protocol you can server you cocos game no problem.

The cocos2d-js is a web application a so it works like any other javascript based web app.

@arunasank for tests using my local network i also use the pyhton web server my guess is it can be used as a trivial web server as well i just run cocos run -p web -host MY_IP

thanks but I still didn’t see the need for webserver. Why would the generated game require it regardless it is simple python one iis apache etc?

Try run the index.html without and open the bowser console and you see what i’m try to explain in here How to host an cocos2d-js web only game?.

Are there any example heroku packages that help get head start ?

Or tutorials to do so ?