At LocaModa, most of our APIs are eventually consumed by ActionScript 3 applications run on large outdoor screens or in users' web browsers. Flash's cross-domain request protection incurres some round-trip latency, which essentially means wasted screen time, which is money, and I'd like to share one way we optimize for this.

We use the excellent Varnish HTTP accelerator in front of our application servers. True, we could easily be serving crossdomain.xml from Tomcat, or Apache, or NginX, but Varnish is the only part of the infrastructure I'm really happy with for the long-term. This is why I decided to serve a static file from Varnish which, officially, doesn't do this.

"Error 843? What the hell is that?" vcl_recv is intercepting requests for crossdomain.xml and returning an illegal, non-standard, stupid error. 843 is meaningful to those familiar with Flash socket connections as the TCP port number for socket policy requests. (I wrote a server for this a while ago.)

In vcl_error, we catch 843's and synthesize a response. The response has a far-future expiration and a 200 response code. These requests are served even faster than Varnish's already blindingly fast cache hits.