是顺序或并行加载的外部JavaScript文件? [英] are external javascript files loaded sequentially or parallel?

查看:129
本文介绍了是顺序或并行加载的外部JavaScript文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我的页面中有多个脚本标签,例如:

if i have multiple script tags in my page like:

    <script src="js/jquery-1.7.min.js" type="text/javascript"></script>
    <script src="js/jquery.jplayer.min.js" type="text/javascript"></script>
    <script src="js/globals.js" type="text/javascript"></script>
    <script src="js/sound.js" type="text/javascript"></script>

我可以依赖以前的代码加载后者的代码已经可用的事实?

can i rely on the fact that code from the previous ones is already available when the latter ones are loaded?

推荐答案

通常,脚本是按顺序下载的(参见此页):

In general, scripts are downloaded sequentially (see this page):


因为JavaScript代码可以改变web
页面的内容和布局,所以浏览器会延迟呈现脚本
标记之后的任何内容,直到该脚本被下载,解析并执行。
但是,更重要的是,对于往返时间,许多浏览器会阻止
下载资源[例如样式表,图像和其他脚本]
脚本之后的文档,直到这些脚本被
下载并执行。

Because JavaScript code can alter the content and layout of a web page, the browser delays rendering any content that follows a script tag until that script has been downloaded, parsed and executed. However, more importantly for round-trip times, many browsers block the downloading of resources [such as stylesheets, images, and other scripts] referenced in the document after scripts until those scripts are downloaded and executed.

这篇关于是顺序或并行加载的外部JavaScript文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆