Link to home
Start Free TrialLog in
Avatar of websss
websssFlag for Kenya

asked on

Sending large KB string of data from server to client - make string smaller size and still use in JS

I have a Asp.net MVC app which sends a float array data to the client

float[320,240]
See attached for the data, its around 1.4mb

I need to dramatically reduce this size, and be able to convert it to the current format in Javascript

Here is the request
 $.ajax({
  type: "POST",
  url: "@Url.Action("CameraChange", "Home")",
  async:true,
  data: "{'cameraId':'" + ID + "'}",
  contentType: "application/json; charset=utf-8",
  dataType: "json",
  success: function (response) {
                 imageTemperatureDataArray = JSON.parse(response.TemperatureDataArray);
  },
   error: function (e) {
       alert("error: " + e.message + ' ');
  }
 });

Open in new window


Then I use it futher down in
 
  $("img#schemesImageSchemes").mousemove(function (e) {
       $('#dataSchemes').text(imageTemperatureDataArray[myX][myY]);
});

Open in new window


Is there a way to reduce this size of the attached
And how would i then convert it in JS ?
floattemparray.txt
Avatar of Shaun Vermaak
Shaun Vermaak
Flag of Australia image

Do you have control over the MVC app and the application running on the client?

You can GZip or something like msgpack
https://msgpack.org/
Avatar of websss

ASKER

Yes, it's one app
When I say client I mean client side /javascript end
ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Is the data coming from a database or a text file? If you are trying to solve a speed problem are you sure the issue is not with the db?  Caching the file as a text file if possible or paging chunks of data via ajax.
Avatar of websss

ASKER

Thanks
Its coming from a file, Dev tool bar shows me 1.4mb of content download.
Avatar of websss

ASKER

Compression is already on
And in chrome Dev tool bar is see gzip accept parameter in header
Its still showing same size on content download as the actual file size
On the chrome dev tools, go on the network tab, check "Disable cache" and if needed "Preserve log", launch your code to download the file, and check the size column for the ajax call line. If you see only one line (1.4MB), that mean your IIS server did not compressed your file. If you see two lines, 1 with the compressed size and the other 1.4MB, you're ok.
If not OK, you need to add the mime type application/json
Avatar of websss

ASKER

thanks, i've got this in my config
    <urlCompression doDynamicCompression="true"  doStaticCompression="true" />
    <httpCompression>
      <dynamicTypes>
        <add mimeType="application/json" enabled="true" />
        <add mimeType="application/json; charset=utf-8" enabled="true" />
      </dynamicTypes>
      <staticTypes>
        <add mimeType="application/json" enabled="true" />
        <add mimeType="application/json; charset=utf-8" enabled="true" />
      </staticTypes>
    </httpCompression>


this is request headers
Accept: application/json, text/javascript, */*; q=0.01
Accept-Encoding: gzip, deflate
Accept-Language: en-GB,en-US;q=0.9,en;q=0.8
Connection: keep-alive
Content-Length: 17
Content-Type: application/json; charset=UTF-8
Host: ommited
Origin: http://ommited
Referer: http://ommited
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.157 Safari/537.36
X-Requested-With: XMLHttpRequest

Open in new window



and this in response headers
Cache-Control: private
Content-Length: 1489534
Content-Type: application/json; charset=utf-8
Date: Tue, 21 May 2019 13:43:28 GMT
Server: Microsoft-IIS/10.0
X-AspNet-Version: 4.0.30319
X-AspNetMvc-Version: 5.2
X-Powered-By: ASP.NET

Open in new window


But its still 1.4mb even if i do the dev tool bar trick
so you see one line here instead 2 like 125KB and 1.4MB :

User generated image
Avatar of websss

ASKER

Yes just one line

User generated image

After disabling cache
User generated image
Avatar of websss

ASKER

ohh IIS didn't have dynamic compression installed (despite it letting me tick that box in IIS)