Why not use JavaScript SDK to make HTTP POST Request to Graph API

  1. Previous
  2. Next
  3. Recent

    1. Signs 'He' May be Cheating on You
    2. 7 Vows of Hindu Marriage - Know What 'Saat Vachans' Mean
    3. RuPay vs Visa vs Mastercard vs American Express- A Comparison
    4. What is RuPay? Everything You Need to Know About India's Domestic Payment System!
    5. Top 10 Online Portals to Find a High Paying Job in India
    6. Top Indians who Revolutionized the IT Sector in India
    7. 8 Initiatives by Narendra Modi that Could Change the Future of the Nation
    8. 8 Work-from-home Jobs for Housewives, Students, and Part timers
    9. Complete Company Registration Process in India - Explained
    10. Change Name in India in 5 Steps - Filing Affidavit, Newspaper Ad & Gazette Notification

While building Facebook apps there may be times when you need to make HTTP POST request to Facebook’s Graph API – like while posting update on user wall.

This is easily possible using FB.api function of JavaScript SDK.

Apart from using JavaScript SDK, an app usually has php SDK as well. So the app is actually loading 170Kb (of JS SDK) and 36kb (of PHP SDK) which makes it a total of 206 kb. In addition to this, your core app files must be having ~40-50kb size. Thus, every-time your app is used, a minimum of ~250kb is downloaded again and again.

There is a specified time limit within which an app must load. By default its 10 seconds. So, if your 250kb file takes more than 10 seconds to load then you’ll app might throw CurlExpection which makes it unusable to everyone.

If your app server is powerful enough to bear such a load consistently then you can use JavaScript SDK in app for simplest of operations. If not, then you should look to minimize the file size, hence load on server.

This is possible by avoiding the use of bulky JavaScript SDK to make HTTP POST/GET request to Graph API. Instead make Ajax calls using JavaScript/jQuery to do the same. This way you’ll cut as much as 169kb data to decrease overall file size by more than 70percent.

You can make Ajax call using JavaScript or jQuery depending on your choice. One thing to note here is that Ajax call is hugely simplified using jQuery but you’ll also have to bear an extra load on ~36Kb (of jQuery). Doing the same using JavaScript only will take less than 1kb.

  • JavaScript sdk + php sdk + your core app files = 250kb+
  • Ajax call using jQuery + php sdk + your core app files = 122kb
  • Ajax call using simple Javascript + php sdk + your core app files = 72kb

You can do all Graph API calls and FQL queries using Ajax instead of JavaScript SDK.

Recommended to read:

  1. HTTP POST request using Facebook’s JavaScript SDK.
  2. Make HTTP POST request using jQuery.
blog comments powered by Disqus