views:

217

answers:

2

I'm working on enabling facebook connect with my website, and it seems to work pretty good so far. However, loading the facebook api library on every page of my site is bogging it way down. All the other php classes that I'm using compile in well under 1 second, but I'm seeing serve times ranging from 3 - 20 seconds just to get the facebook api loaded up. Is there anything I can do to speed up facebook connect? Is it just because I'm on a (mt) shared server?

A: 

I'm not sure if I'm just stating the obvious, but do you need to load the API on every page of your site? Is the user interacting with facebook on every page? Is there any way that you could limit the API usage by redirecting to specialized endpoint when you need to communicate with facebook.

Joel Martinez
I was under the impression that the API was needed in order to run facebook connect. Cutting it out entirely would (to state the obvious :) obviously speed things up quite a bit.
Wade Williams
What I meant was, do you need to run facebook connect on every page? To use Nick's point, if you are using it to pull user data, then you could cache it for 24 hours, and in that time period, not load the API at all.
Joel Martinez
A: 

Facebook allows you to cache user data for 24 hours. This can help a lot when you are doing a lot of queries to Facebook for heavier data like friends. This does not help for things like profile pics which are not easy to cache but can save you a lot in some places.

Keep in mind that some of the slow down can be in the cross site javascript which really has nothing to do with your server but can really add up. An application like fiddler will help identifying where the slow down is in these cases.

Nick
The bottleneck seems to be on the server side, not the client. So measuring http traffic on the client side with fiddler doesn't seem like it will help - because the page is being loaded in a decent amount of time after it is done being dynamically created on the server side. Before the server puts out any headers, however, the FB api is taking 3-20 seconds to be created. Caching user data for 24 hours can be useful in some cases -- I am new to facebook connect so correct me if mistaken; you need to validate an existing FB session using the API?
Wade Williams
You still need to validate but you can potentially cache everything you need so that you only take the hit when they first log in.
Nick