Whenever I check my website on gtmetric, google Insights, Pingdom etc... I always get feed back of render blocking JS
Currently I enqueue all my scripts as so:
<head> <link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css"> <link href='https://fonts.googleapis.com/css?family=Roboto:400,300,700' rel='stylesheet' type='text/css'> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css"> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script> <script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script> </head>
I was wondering if there was a better way to enqueue so that the scripts could be combined and the JS in particular added to the footer?
I have seen that i could enqueue via functions.php
as in this page external javascript
however there seems to be some stigma around that in that it may not work correctly.
Is there any advice? tips?
I have since tried to removed the scripts/styles from the ...
and inserted in functions.php as follows:
function external_scripts() { wp_register_script('googleapis', 'https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js', array('jquery'), true); wp_register_script('bootstrap', 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js', array('jquery'), true); wp_enqueue_script('googleapis'); wp_enqueue_script('bootstrap'); } add_action( 'wp_enqueue_scripts', 'external _scripts' ); function external_styles() { wp_register_style('bootstrapcdn', get_template_directory_uri() . 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css'); wp_register_style('maxbootstrapcdn', get_template_directory_uri() . 'https://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css'); wp_enqueue_style('bootstrapcdn'); wp_enqueue_style('maxbootstrapcdn'); } add_action( 'wp_enqueue_style', 'external _styles' );
But this seems to have broken the site... Now images do not load and also the menu does not drop down on hover.
ideally I would like to defer :
wp_register_script('jquery', 'https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js', true);
and async
wp_register_script('bootstrap', 'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js, true);