【发布时间】:2015-07-02 07:58:31
【问题描述】:
我正在使用以下内容在我的网站上加载广告
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script type="text/javascript">
var adWidth = $(document).width();
google_ad_client = "ca-pub-6777348526535979";
if ( adWidth >= 768 ) {
google_ad_slot = "3870513647";
google_ad_width = 728;
google_ad_height = 90;
} else {
google_ad_slot = "1127560842";
google_ad_width = 320;
google_ad_height = 50;
}
</script>
<script type="text/javascript" src="//pagead2.googlesyndication.com/pagead/show_ads.js"></script>
它工作正常,但我认为我可以进一步优化广告投放。我想异步加载 jquery,因此下面的脚本必须等待 jquery 被加载。
<script type="text/javascript">
var adWidth = $(document).width();
google_ad_client = "ca-pub-6777348526535979";
if ( adWidth >= 768 ) {
google_ad_slot = "3870513647";
google_ad_width = 728;
google_ad_height = 90;
} else {
google_ad_slot = "1127560842";
google_ad_width = 320;
google_ad_height = 50;
}
</script>
<script type="text/javascript" src="//pagead2.googlesyndication.com/pagead/show_ads.js"></script>
我怎样才能做到这一点?
【问题讨论】:
标签: javascript jquery asynchronous