• Resolved jkin

    (@jkin)


    Please help to make sure what the following code is wrong.

    //
    // Eliminating Render Blocking Scripts
    //
    
    function optimize_jquery() {
    if (!is_admin()) {
    wp_deregister_script('jquery');
    wp_deregister_script('jquery-migrate.min');
    wp_deregister_script('comment-reply.min');
    $protocol='http:';
    if($_SERVER['HTTPS']=='on') {
    $protocol='https:';
    }
    wp_register_script('jquery', $protocol.'//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js', false, '3.6', true);
    
    wp_enqueue_script('jquery');
    }
    }
    add_action('template_redirect', 'optimize_jquery');
    
    }

    The result is as below.

    The code snippet you are trying to save produced a fatal error on line 20:

    syntax error, unexpected ‘}’, expecting end of file

    • This topic was modified 7 years, 10 months ago by jkin.
    • This topic was modified 7 years, 10 months ago by jkin.
Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter jkin

    (@jkin)

    I have tried to add the closed ‘}’.. yet, same result.

    Plugin Author Shea Bunge

    (@bungeshea)

    The issue isn’t tat you are missing a } – instead, there is an extra } at the end of the snippet which shouldn’t be there.

    So this code should work without errors:

    function optimize_jquery() {
    	if ( ! is_admin() ) {
    		wp_deregister_script( 'jquery' );
    		wp_deregister_script( 'jquery-migrate.min' );
    		wp_deregister_script( 'comment-reply.min' );
    		$protocol = 'http:';
    		if ( $_SERVER['HTTPS'] == 'on' ) {
    			$protocol = 'https:';
    		}
    		wp_register_script( 'jquery', $protocol . '//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js', false, '3.6', true );
    
    		wp_enqueue_script( 'jquery' );
    	}
    }
    
    add_action( 'template_redirect', 'optimize_jquery' );
    Thread Starter jkin

    (@jkin)

    This just works!!

    Thank you very much indeed.

    Plugin Author Shea Bunge

    (@bungeshea)

    No problem!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Eliminating Render Blocking Scripts’ is closed to new replies.