Download js for Facebook Connect on demand

Our site uses Facebook Connect to enable users to post updates to their Facebook. The Javascript that allows this must be loaded directly through the Facebook feature loader , and we loaded it on every page where the user might want to connect to Facebook. Unfortunately, since some users block Facebook at their workplace, this makes our site freeze for these users.

Ideally, we would like to load the js through the function loader just before we actually need it. However, we do not know if this function will be needed as long as the page on which it will be used has already been loaded. Specifically, the user will open a dialog box and check "post to facebook" before submitting the AJAX form (but not leaving the page). It is at this point that we would like both to load the Facebook js and immediately execute the code to open the dialog. Is there a sane way to do this?

+2


source to share


1 answer


Essentially, you want to load js on demand after the page has already loaded. This is definitely doable; there is a decent article that summarizes how you can do this here:

http://ajaxpatterns.org/On-Demand_Javascript

I also like the following little features from phpjs.org:



http://phpjs.org/functions/require_once:503

http://phpjs.org/functions/include_once:434

http://phpjs.org/functions/include:433

+1


source







All Articles