Posts

Showing posts from April, 2017

JSON bag - bInary multipart JSON response

Image
In a scenario in which I am involved we have an embedded server that answers the status of activities and devices combining structured data (JSON) and medium sided binary data (images). This post and the associated github repository (here) presents a AJAX response that combines JSON data with one or more binary payloads. The objectives are the following: avoid base64 bandwidth and decoding overheadavoid custom encodings such JSONB/MessagePack that are slow in browser decodingreduce number of requests or more complex production logic (if not using HTTP 2.0 Server Push)usable for file serializationgraceful degradation (Content negotiation and JavaScript support)The approach is the following: data encoding, transferred as JavaScript ArrayBuffer, that contains readable header, main JSON and then binary blocks each with a JSON headerprocessing on the client side that patches the JSON replacing stub URIs with the new Blob URIs. server-side generation that can produce both the JSON bag and a …