Topic-icon Change JFBConnect loading to the end

Active Subscriptions:

None
5 years 5 months ago #64780 by skyfranky
Hi

I have a site that target world users including China. Facebook and Google are blocked in China, and my site is loading very very slow in China because JFBConnect can not connect to FB and Google. See:
www.screencast.com/t/MjoEl5Ru39Z

Is there a way to disable JFBConnect from connecting to FB & Google when the user IP is from China? when my site loads, is it possible to move JFBConnect loading to the end so that everything will be loading fast, and not blocked by it?
The topic has been locked.
Support Specialist
5 years 5 months ago #64782 by alzander
The way we load all of the social network Javascript libraries is meant to be optimized as best it can for any site, including those that block those libraries. For instance, many ad-blockers or privacy extensions also block those files. It shouldn't be a major cause of your site to run slowly.

If you're loading out of China, I'd recommend using the 'Network' tab in Chrome (or your browser of choice) and see how the Facebook library is blocked. Usually, it's an instant block with an error code.. not a timeout error. That means the page should still be just as responsive as it would be with JFBConnect disabled.

Another way to test is simply disabling the JFBCSystem plugin. That's what enables all of our Javascript inclusions and other features. If it still loads slow, JFBConnect is not the cause.

Unfortunately, China makes many sites and pages run slowly. If you continue to think it's JFBConnect though, please let us know how long it takes for those files to timeout and how long the page is loading in general?

Thanks,
Alex
The topic has been locked.
Active Subscriptions:

None
5 years 5 months ago #64789 by skyfranky
when I disable JFBconnect plugin, these error gone
www.screencast.com/t/MjoEl5Ru39Z

Did you Defer Your Scripts?
davidwalsh.name/script-defer
The topic has been locked.
Support Specialist
5 years 5 months ago #64793 by alzander
When you disable JFBConnect, you're removing the scripts entirely, so you won't see that error. Even if you defer the scripts, they will still try to load, China will block them and you'd get that error. Deferring won't fix the error and allow them to load. The problem is that they are being blocked and there aren't ways around that.

Again, if you can let us know how long it takes for those errors to appear (you can use the Network tab in the Developer Tools area), why you think those scripts being blocked is causing the page to run slow and what effect that's having, that's more helpful to understand what's going on and what we can do to help fix things.

Thanks,
Alex
The topic has been locked.
Active Subscriptions:

None
5 years 5 months ago #64794 by skyfranky
The topic has been locked.
Support Specialist
5 years 5 months ago #64796 by alzander
Thanks for sending that.

Unfortunately, we don't know how to improve that. We use Facebook's recommendations for loading their Javascript:
developers.facebook.com/docs/javascript/quickstart

What is your recommendation on how to improve that? Even if the Javascript is deferred, the browser is still going to try and load it, which would be an 18s delay. If we do that, there's also other issues that can come along with that because the Javascript expects to be loaded per their recommendations, so other issues can crop up if the timing is moved for users where it does work.

If you have suggestions or aware of recommendations from Facebook on how to minimize this issue, we're all ears. There's simply not a silver bullet that we're aware of. The only 'hammer' recommendation I can give is to remove the Facebook Javascript altogether. If you're not using the FB widgets (like button, comment box, etc) and want to switch to using the authentication redirection ("Show Login Credentials In Popup" - No), then the Facebook Javascript can be removed. There's a line or 2 of code you can use to remove that and we can gladly help provide it.

Thanks,
Alex
The topic has been locked.
Active Subscriptions:

None
5 years 5 months ago #64816 by skyfranky
one soution I can think of is to add country detection by user IP. So when users are from mainland China, Do not show FB login and disable connecting the FB SDK.
The topic has been locked.
Support Specialist
5 years 4 months ago #64828 by alzander
It's a possible suggestion, but IP detection requires additional services to look up each IP and determine the location. Many times, those services have an additional monthly fee. Alternatively, we'd have to bundle in a IP database and region lookup into JFBConnect, but that can get out of date over time.

Unfortunately, neither of the above options are things we're currently planning to do. IP detection and action is better handled by firewall extensions that do that all the time and adding a large database of IP lookups (and the time requirement added to each page load to perform the lookup and take action) is not something we want to include in JFBConnect.

My best suggestion would be:
1) Set the "Show Login Credentials in Popup" setting in the Facebook configuration area to 'No' - This uses a different authentication flow that does not require the Facebook Javascript library to be loaded.
2) Manually remove the Facebook Javascript library from JFBConnect so it's not loaded on any pages - We can give you a few lines of code to comment out to do this, but it prevents all Facebook widgets from loading.

The above leaves Facebook login intact for those that can use it, but disables all other Facebook Social Widgets. Things like Authentication, Channels, Open Graph and other server based features would still work.

I hope that helps,
Alex
The topic has been locked.
Active Subscriptions:

None
5 years 4 months ago #64833 by skyfranky
1) Set the "Show Login Credentials in Popup" setting in the Facebook configuration area to 'No' - This uses a different authentication flow that does not require the Facebook Javascript library to be loaded.
=> This was already set, but still loading FB library

2) Manually remove the Facebook Javascript library...
=> I can't as users outside China need FB login
The topic has been locked.
Support Specialist
5 years 4 months ago #64836 by alzander
As mentioned in my suggestion:

The above leaves Facebook login intact for those that can use it, but disables all other Facebook Social Widgets. Things like Authentication, Channels, Open Graph and other server based features would still work.

When you turn off the authentication in popup, JFBConnect still allows Facebook authentication by redirecting the user to Facebook where they authenticate and are returned back to your site. That flow does not require the Facebook Javascript library at all.

If authentication is currently working how you want, please try editing the following file to remove the Facebook javascript inclusion:
/components/com_jfbconnect/libraries/provider/facebook.php
Around line 404, you should see:
JResponse::setBody($newBody);
Comment that line out (put 2 forward slashes in front of it, like '//'). Then, the Facebook Javascript library should no longer load but authentication should still work.

Please test and let me know how that goes!

Thanks,
Alex
The topic has been locked.