Discourse stripping ESI tag when adding custom footer

The footer is passed to the SPA as a JSON blob.

So unless you teach varnish how to fiddle with the json you are not going to have any luck there.