In theory, if you made the AJAX request directly to the Spark Cloud (without any sort of proxy to hide the access token), it would take one less hop than if you sent that AJAX request to the server hosting the web page (the RPi?) which then proxies the request onto the Spark Cloud. The Spark Cloud still has to send a request (for Spark.variable() or Spark.function()) to your Core and back through the whole round trip again. The whole thing could take a second or two to complete.
If you ran it off a local cloud on the same network, then you’ll eliminate the dozens of hops across whatever networks it takes to get from your browser to your Core and back again. If they’re on the same subnet or same local network, a local cloud request would take much less time.
If that’s still too slow, you’ll have to communicate from your web browser directly to your Core. There are a few options that are web-browser friendly, but they may not be easy to implement:
- Plain GET/POST HTTP server (easiest)
- PubSub server using bayeux protocol (like CometD)
- Web sockets
- WebRTC server (still pretty new)
I know the HTTP server can be done on the Core now, and there are a couple of libraries floating around that can get you up and running quick. The other three are options that are browser-friendly but don’t have any sort of library yet (that I know of), so that implementation would be entirely up to you.
If you have the resources like an extra computer or Raspberry Pi (or similar), I would try the local cloud first since it would be similar to what you’re already used to using. If that doesn’t work, try running an HTTP server directly on the Core.