每当我在gtmetric、google Insights、Pingdom等网站上查看我的网站时。。。我总是收到渲染阻塞JS的反馈
目前,我将所有脚本按如下方式排队:
<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>
我想知道是否有更好的方法来排队,这样脚本就可以组合起来,特别是JS添加到页脚?我看到我可以通过functions.php
如本页所示external javascript
然而,似乎有一些污名围绕着它,因为它可能无法正常工作。
有什么建议吗?小费?
我已经尝试从。。。
并插入函数中。php如下:
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\' );
但这似乎破坏了网站。。。现在图像不会加载,悬停时菜单也不会下拉。理想情况下,我希望推迟:
wp_register_script(\'jquery\', \'https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js\', true);
和异步wp_register_script(\'bootstrap\', \'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js, true);