-2
在将jQuery脚本加载到async
之后,出现$(document).ready()
上的“$ is undefined”错误。
以下是我的代码的简短版本。在我将async
属性添加到加载jQuery的我的<script>
标记之前,它正在工作。
我这样做是基于由谷歌网页洞察以改善我的网页的表现
推荐<script src="/scripts/jquery.min.js" async></script>
<script>
$(document).ready(function(){
//Some variable initialization
});
</script>
当然,你得到的,b因为当第二个脚本被执行时第一个脚本还没有加载......这就是'async' _means_。你需要'推迟'而不是 - 这会确保和保证执行顺序。 – CBroe
使用谷歌托管的库。 –
但会延期影响页面加载时间在谷歌网页洞察检查。 –