【发布时间】:2013-11-15 04:34:55
【问题描述】:
我希望根据 PageSpeed Insights 改进我的页面加载时间/排名。问题是我的很多脚本/css 都在渲染阻塞。我怎样才能成功地使用 wp_enqueue_script() 来帮助我将大部分脚本放入页脚而不是页眉(wordpress)。
CSS 示例
<!-- CSS -->
<link rel="stylesheet" href="<?php echo get_option('siteurl'); ?>/wp-content/themes/<?php echo get_current_theme() ?>/style-jquery-ui-1.8.6.custom.css" type="text/css" />
<link rel="stylesheet" href="<?php echo get_option('siteurl'); ?>/wp-content/themes/<?php echo get_current_theme() ?>/style-prettyPhotoCSS.php" type="text/css" />
脚本示例
<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js?ver=3.7.1'></script>
【问题讨论】:
-
更改模板中的输出位置
-
@charlietfl 你能解释一下怎么做吗?我以前从来没有这样做过
-
你实际上想要css在头,js在脚。
-
您是否阅读过解释
wp_enqueue_script工作原理的文档?以及如何将脚本打印到页面上?有据可查 -
BTW...css 不应该进入页脚,否则页面在加载 html 时不知道如何设置样式。 CSS 应该始终在头部
标签: javascript css wordpress performance