send xhr post compressed - javascript

I have a "monitored" application. Every minute the web client do a POST to my services sending a JSON with some data. The json is big (circa 20Kb each time).
Is there a way to send a "compressed" version of the data?
Do I need to do it applicatively?
I'm using jQuery client side, and can send custom headers from the server.

Well you can also compress data in client side with the library https://github.com/cscott/compressjs. There are multiple methods the choice should be made based on your input data and the resources available in client side.
Besides using the POST request you may try the Websocket connection which should be better for sending larger input data.

It might be that the full json post is not required, if it possible to only post the data that has changed sinch that last post then that would greatly reduce the amount of data sent.
if that not possible you could reduce the size of the data posted using JSONH
From what I've read using web sockets might not use dramatically less bandwidth then http post, but there is a good article here on optimising websockets

Related

How to persistently cache data fetched from remote server with javascript

I am building a reactjs (with hooks) web app which presents the user some data fetched from remote server pages (using a simple proxy).
Data on remote server changes about once per week, so I would like to persistently cache data (for example using LocalStorage) on the client, until server side pages are not updated, for a better user experience.
I'm using axios for data fetching, but I could also use a basic fetch.
The problem is that I can't understand how to cache data on the client until any update on the server: I see for example axios supports caching mechanisms (also using interceptors), but no way I can specify something like ETag or If-None-Match request header, but I can only specifiy a fixed amount of time before the cache is invalidated.
It is possible I'm missing something obvious, and that I'm asking something unfeasible...
I can think of a few ways solving this:
1) using a DDP protocol https://en.wikipedia.org/wiki/Distributed_Data_Protocol or some polling mechanism (e.g. fetch every x minutes)
2) add some "expireAt" timestamp in the response itself and use that one on the client to figure out when to check again for updates
3) using websockets with some pub/sub mechanism
They all have their ups and downs and you'd need to check if they are feasible for your application.
Best,
Sebo

Meteor: Sending file through HTTP library to Echonest for analysis

I am using Meteor for a web application project and am trying to send a file using the HTTP library and get back a JSON object using a get request. I need to send a POST request to the echonest server where the file is sent as a binary data object. From there, I need to make two GET requests: one to get the url and one to get the data at that url. The last two steps are not a problem, but I'm finding it very difficult to send the raw binary data. Here's what I've found so far:
The Meteor HTTP library cannot send binary data in a POST request because it calls JSON.stringify on the data being sent.
An XHR cannot be used to send the data from the client because the server I am trying to communicate with blocks client-side connections to their service.
So what I want to know is if there is another library/package that can be used with Meteor to send the binary data?
Alternatively, is there a way to get an XHR request to work on Meteor server-side?

Compress text data in javascript and send it via AJAX

I develop web application that supposed to communicate with server using jQuery/AJAX/JSON. Just was curious, is it possible to compress somehow text data before send it to server and extract it there? Are there any already implemented JavaScript compressors?
In other words, how to implement next scenario:
Compress text data on client side using JavaScript
Send compressed data to the server
Decompress data on the server side
any ideas?
Yes, any compression algorithm written in JS will do, or look into setting compression settings in the HTTP headers of the requests you're sending.

High traffic solution for simple data graph website

I'm building a single page website that will display dynamic data (updating once a second) via a graph to its users. I'm expecting this page to receive a large amount of traffic.
My data is stored in REDIS and I'm displaying the graph using Highcharts. I'm using ruby / Sinatra as my application layer.
My question is how best should I architecture the link between the data store and the JavaScript graph solution?
I've considered directly connecting to REDIS but that seems the least efficient . I'm wondering whether a XML solution where ruby builds an XML file every second and then Highcharts pulls data from there is the best as therefore the stress is only on hitting that XML file.
But I wanted to see whether anyone on here might have solved this previously or had any better ideas?
If the data is not user-specific, you should cache it into a representation that is easily read by the client. With web browsers, JSON might be a better choice.
You can cache it using Redis itself. (Memcached, Varnish are other options) You should cache it every time the data arrives and must avoid transforming the data on each request. The requests must simply serve pre-computed information from the cache (like you do with static information)
For a better experience on the client side, you should minimize the amount of data you are downloading from the server. JSON serves this purpose better than XML.

Implementing a very small HTTP server in c/c++ and want to use AJAX

I want to have a dynamic webpage that automaticly updates some information, this information should be received from my c/c++ application using HTTP. I have set up a socket and can send HTML and Javascript files to the browser.
I don't know how to move on. How to encapsulate my data into XMLHttpRequest objects? Or maybe this isn't the way to go? The problem is that my c/c++ application will be run on an embedded system that can't really support php or something like that.
I can't really understand how XMLHttpRequest works, I only find a lot of client examples on the web and not much about how a server should handle it.
A server should handle it as any other request. From the servers point of view, it's a normal HTTP request. Return the data that the client asks for! This is usually a HTML fragment, some XML or some JSON.
Ajax just send normal HTTP GET POST ... request, you should make sure your response header is correct, such as Content-Type.
How do you send information to the browser? The browser is client-side. To get information, you must either query the server (which you say is written in C++). If you want your client to receive request, you should probably emulate a server-like behavior using NodeJS.

Categories

Resources