Quantcast
Channel: responsive – WordPress.org Forums
Viewing all articles
Browse latest Browse all 16569

Niall Kennedy on "disable facebook loading if responsive view"

$
0
0

Two issues:

  • Preventing the Facebook SDK for JavaScript from downloading and saving the bandwidth in the process
  • Facebook SDK for JavaScript loads but you would like to disable some or all social plugins.

In your JavaScript you are probably computing the size of the currently available viewport and making some decisions based on the size, similar to a CSS media query. If width 480 pixels or less do not load these JavaScript.

The Facebook SDK for JavaScript loads asynchronously through wp_enqueue_script in the footer. The asynchronous JavaScript checks for the existence of a facebook-jssdk DOM ID on the page and assumes the JavaScript file has already been loaded if found. Adding your own element with the ID of facebook-jssdk would short-circuit this loader and fbAsyncInit() would not be called.

If you would like greater control over when or if social plugins load on the page set the xfbml value passed in the facebook_jssdk_init_options WordPress filter to false and call FB.XFBML.parse on a parent of the social plugin element parent directly.


Viewing all articles
Browse latest Browse all 16569

Trending Articles