0

I have this app, where the client has very low upload speed, so I need to compress the JSON they send to the server in order to improve their speed.

I've checked several (probably all) questions on here about pako, gzip, zlib, etc... and can't get them to work for me.

I've tried defining the request like this:

.factory('Form', function ($http, DateUtils) {
        return {
            save: function(formDTO){
                var req = {
                    method: 'POST',
                    url: "api/form",
                    headers: {
                        'Content-Type': 'application/json',
                        'Content-Encoding': 'gzip'
                    },
                    data: formDTO,
                    transformRequest: []
                };
                console.log('in the form.service.js');
                return $http(req);
            },
            load: function(id){
                return $http.get("api/form/"+id)
            }
        }
    });

And it basically sends an empty body.

I've tried installing ngPako and doing the request like this:

.factory('Form', function ($http, DateUtils, pako) {
        return {
            save: function(formDTO){
                var newFormDTO = pako.deflate(formDTO, {to: 'string'});
                console.log('this is the deflated data', newFormDTO);
                console.log('in the form.service.js');
                return $http.post("api/form", formDTO);
            },
            load: function(id){
                return $http.get("api/form/"+id)
            }
        }

And the browser just crashes on me

Is there anyway to compress data with angular?

Olearn
  • 49
  • 12
Steven
  • 1,236
  • 1
  • 13
  • 37
  • Did you have a look at [JSONC](https://coderwall.com/p/mekopw/jsonc-compress-your-json-data-up-to-80)? – Nicolae Olariu Jul 13 '18 at 14:28
  • I have, but I can't get it to work in an AngularJS environment – Steven Jul 13 '18 at 14:45
  • How did you try to use it? – Nicolae Olariu Jul 13 '18 at 14:49
  • I installed it with npm, but it won't pick it up in the dependencies, I get a bit lost with front-end tech, but I take it I need a bower module so it can be used in AngularJS? – Steven Jul 13 '18 at 14:50
  • It depends on your boilerplate. If you do have bower and you're using it, for sure you need to install jsonc through bower and then try again - depending on your build logic - it should show up in your vendors/dependencies file. – Nicolae Olariu Jul 13 '18 at 14:53
  • ok, sorry for mental meltdown there, so I've done that, put it in index.html as all others, copied the exported module name (JSONC) to my module.js and it still won't let the app start as it believes JSONC isn't there – Steven Jul 13 '18 at 15:00

0 Answers0