Compress text data in javascript and send it via AJAX - javascript

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.

Related

Stock chart transfer between server/website

I'm coding a private webapp that can pick some data from a source (yfinance, panda, ...) and generates a time series. Basically, I want to be able to click on any of the Dow Jones stocks with an HTML btn or whatever, which will send a request to my backend server to generate such chart using python, R or any alternative.
Two possibilities:
I generate the chart and figures on the client's side, by sending the data from the server to the client on a JSON format (which seems really unproductive).
Or, I make all computations on backend, following an HTTP request from the client, generate the chart and send it to the client (my computer).
The question is, can I send such chart, from the server to the client without uploading it as a png and transmit the link through AJAX etc. May I get the output of a python function and send it ?
To summarize: Can a .png file might be sent from a server to an online webapp, any ideas ?
Thanks for your comments, this is a technical question and this might be useful for future requests. Also, I plan to code everything using Django framework.
Planning everything so nothing has been built yet.

Can AngularJS save/write file to server without any server side technology?

I would like to know if AngularJS can save some file without need of NodeJS, PHP, Java or similar server side technology. Just pure JavaScript. I have seen many examples of AngularJS upload scripts. But it did not fully understood if AngularJS alone can do it. In those examples, files seem to be uploaded as blob, and then represented automaticly in browser when upload occurs. But that file or image is never saved on server, I mean on the disc of the server. I would like to achieve that.
I have checked this links:
File Upload using AngularJS
AngularJS: how to implement a simple file upload with multipart form?
But seems or mentioned blob technique is used, or it is some server side technology involved. I would like to have upload script where I would not have to worry about server-side handling, so if possible, upload would be done all via AngularJS/JavaScript.
So can it be done, with pure AngularJS/JavaScript?
I would appreciate the example..really don't know how to do this?
AngularJS is client side code only. By it self it has no power over the server from which it served. After the code is sent to your browser it has no connection or reference to the server side environment.
So the short answer is no.
The long answer is that you need a script/program running on your server which can handle the file input from a request. That request can be simple multi-part upload or a two way web socket connection, but anyway you need a logic which handles on the server side the request. Because Node.js server is written in JavaScript, you can write a full JavaScript implementation of file upload, but that's no longer just a simple AngularJS code.

send xhr post compressed

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

Accessing JSON data from JavaScript on a web page

I have a moderately large JSON data file and I want to access it from the JavaScript code on my web page. What is the simplest way to do that? Should this be done on the client side, or is it better to do that on server side?
It can't be done on the client side. Use server to read and print content on page in needed for javascript format. If you want save it you also need to send content to server.

Exchange compressed data between web client and server

On client side i am using jQuery and JSP and server side i am using Spring MVC. My question is can we send and receive data in compressed format i.e a client and server will exchange its data in a compressed format. How can i do that? please anybody explain me in brief. An example be too good.
you can try GZIP-ing the response sent from the server. This link might help .
sidenote: AFAIK, JSP is server side, not client side

Categories

Resources