framework7

Open full view…

JSON Compression

vinaysamant
Sat, 30 Sep 2017 09:58:14 GMT

i am collecting JSON feed from Wordpress Website & showing it in app. Everything works perfect and my app is on app-strore and people are enjoying it. I want improve it to make it faster to load data. I want to compress JSON. My own server hosted, so i can make any changes. Can someone please guide me about this, i mean how to call for and get JSON data gzipped and use it... $$.ajaxSetup may help to setup headers??

leroysteding
Mon, 09 Oct 2017 11:26:48 GMT

I am trying to do the same thing (collecting data from wordpress website. But i can't get the data in my app. Could you sent me an example of how youve done it?

Lailton
Mon, 09 Oct 2017 21:14:08 GMT

do you find the way? It is interesting

vinaysamant
Sun, 15 Oct 2017 07:31:05 GMT

hii leroy... sorry for not replying earlier... wordpress has JSON API. Your can google online and check for WP JSON API V2 .. you will get lot of code etc.. what i am doing is : 1. i have set global variable url = "http://mywpwebsite.com/wp-json/wp/v2/" 2. Then i call $$.getJSON(url + "posts/?per_page=10&categories=23,24" , function (json) {/* here i get full JSON data and i can use it. */ $$.each(json, function (key, value) {/*loading data in my a block variable*/} }); 3. Then var page = me.getCurrentView().activePage; $$(page.container).find('#latest').html(block); 4. you can check my 2 wordpress apps online https://play.google.com/store/apps/details?id=com.vinaysamant.dhanlabh & https://play.google.com/store/apps/details?id=com.punashcha.cordova ... both cordova app developed using F7... ***Special Tip : you can get data from any wordpress site as JSON API is not inbuilt and unrestricted.. so you can as well write an aggregator...

NikolayKuznetsov
Sun, 15 Oct 2017 16:02:23 GMT

> @vinaysamant > Can someone please guide me about this, i mean how to call for and get JSON data gzipped and use it… $$.ajaxSetup may help to setup headers?? Try add header Content-Encoding: gzip If it isn't helped change call $$.getJSON() to $$.get() and encode text data to json object in callback function.

neekfenwick
Thu, 19 Oct 2017 07:58:51 GMT

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Encoding .. I don't know $$.ajaxSetup at all but no-one seems to have mentioned Accept-Encoding header yet.

vinaysamant
Thu, 19 Oct 2017 08:35:11 GMT

I am sorry for replying late, we have Diwali (biggest festival of lights) here in India.. I tried to set Accept Encoding header in ajax setup.. looks like that works only with ajax command and not shortcust commands like getjson.. I have this experience otherwise also, which is actually strange. as explained earlier, this app is for wordpress site using WP REST JSON API V2. i have some articles protected on that site, accessible to limited number of members. Now i use responsive page on mobile to "login" people in app. This session is maintained by WP for very long time nicely. After login when i call getJSON, i manage to read protected articles, this means getJSON passes authentical headers or session cookie properly using which protected article data is served properly.. this is all perfect.. But when i use post command on REST JSON, to submit comment, it says you should login to comment. Surprisingly i have enabled anonymous comments on my website, but it do es not work on app. Is this expected behavior or kind of bug?? And in this case, what header or variable i should pass to post comment. Can someone please guide me in this??