Reducing json string size by shortening variable names

I have some json formatted data that I parse using JSON.parse. I have a problem with varialble name lengths:

MyObjectName.SuperLongPropertyName; MyObjectName.AnotherLongPropertyName; 

etc. I am using JavascriptSerializer and custom JavascriptConverter to generate json. It is used in several ajax calls, and the data is around 70K.

However, if I could change the variable to

  aa; ab; 

which could shave half the size of a json string.

I can easily change the serialization / deserialization classes on the server. However, on the client side, this would be more complicated, because I use these objects everywhere in my code. And then, even if I manage to change the variable name, then there will be quite complicated code for debugging in the javascript debugger.

What are some good suggestions for: a) converting existing variable names on the client, and b) maintaining readability and debugging?

Thanks.

+4
source share
1 answer

Use transparent gzip HTTP compression . Then your server compresses the transmitted data on the fly and the web browser decodes it again.

gzip does exactly what you suggested, only better. Instead of choosing static aliases for some long duplicate names, gzip selects aliasses for all names and assigns the shortest of them to the most typical aliases. In addition, gzip does not care about syntax and therefore can assign , "SuperLongName": { (including punctuation and spaces) to one character.

+7
source

Source: https://habr.com/ru/post/1390418/


All Articles