Plugin Directory


Opened 4 years ago

Closed 4 years ago

#2028 closed enhancement (duplicate)

Sharing: change how resources are loaded to allow for defer loading

Reported by: bassjobsen Owned by: tmoorewp
Priority: normal Severity: normal
Plugin: jetpack Keywords: sharing enqueue defer loading
Cc: jeremy+wp@…


I wrote a plugin for defer loading javascript, see: http://wordpress.org/plugins/wp-defer-loading/. This plugin requires all javascript enqueued right with setting dependency properly.

Jetpack sharing plugin write javascript code direct to output (page) i understand why, but i also think it is the wrong way to do.

Examples of this issue are in sharedaddy/sharing-sources.php; js_dialog() and several display_footer() / display_header() functions.

One possible solution will be to let the function mentioned above store their data in a global variable. After all function calls call a function which use the global to write right enqueued javascript.

Example for the js_dialog() function:

public    $js_dialog_data; // array as global

	public function js_dialog( $name, $params = array() ) {
		//if($name!=='facebook') return;
		$defaults = array(
			'menubar'   => 1,
			'resizable' => 1,
			'width'     => 600,
			'height'    => 400,
		$params = array_merge( $defaults, $params );
		$opts = array();
		foreach( $params as $key => $val ) {
			$opts[] = "$key=$val";
		$opts = implode( ',', $opts );


After all js_dialog() call you should call by example:

public function parse_js_dialog_data()
         wp_register_script( 'parse_js_dialog_data', plugin_dir_url( __FILE__ ).'parse_js_dialog_data.js', array( 'jquery' ), '20121205' );
	 wp_enqueue_script( 'parse_js_dialog_data' );
	 wp_localize_script('parse_js_dialog_data', 'parse_js_dialog_data_options', $this->js_dialog_data);

With parse_js_dialog_data.js:

	jQuery(document).on( 'ready post-load', function(){
			jQuery.each( parse_js_dialog_data_option, function( name, options ) {
			  jQuery( 'a.share-'+name ).on( 'click', function() {
				window.open( jQuery(this).attr( 'href' ), 'wpcom'+name, options );
				return false;

Change History (3)

comment:1 @jeherve4 years ago

  • Cc jeremy+wp@… added
  • Keywords Jetpack removed
  • Summary changed from Jetpack sharing plugin not ready for defer loading to Sharing: change how resources are loaded to allow for defer loading
  • Type changed from defect to enhancement

Related: #1824

comment:2 @jeherve4 years ago

Related: #2032

comment:3 in reply to: ↑ description @jeherve4 years ago

  • Resolution set to duplicate
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.