1、页面直接就有,或者document.write页面加载同步输出

其实就是当script是页面初始加载的一部分的情况,script是同步的,只有在上一个加载并执行完才会进行下一个script加载。
当然,可手动设置异步:async="async",页面加完,循序依次执行

<script src="http://localhost:8083/-0test/test.js?1"></script>
<script src="http://localhost:8083/-0test/test.js?2"></script>
<script src="http://localhost:8083/-0test/test.js?3"></script>
<script src="http://localhost:8083/-0test/test.js?4"></script>
<script src="http://localhost:8083/-0test/test.js?5"></script>
<script src="http://localhost:8083/-0test/test.js?6"></script>

2、页面中只有js增加的script,或是说是页面加载好后再js增加script

js全部执行完后,并且script已全部成功添加,新增的script才会执行,并且依次顺序执行。
所有ie也是如此

html文件

<div id="info"></div>
<script>
var s = document.createElement('script');
s.src = 'http://localhost:8083/-0test/test.js?5';
document.body.appendChild(s);
var s = document.createElement('script');
s.src = 'http://localhost:8083/-0test/test.js?6';
document.body.appendChild(s);
</script>

test.js文件

var s = document.getElementsByTagName('script');

s = s[s.length - 1];

document.getElementById('info').innerHTML +='<p>'+ s.src;

输出

http://localhost:8083/-0test/test.js?6
http://localhost:8083/-0test/test.js?6

3、js同时增加多个script,页面中已存在其它script

这种情况比较复杂,而且一般不会发生

只有在所有页面中的script加载并执行完后,新增的script才会执行,并且依次顺序执行。
但,确实是在?2位置被增加的,也就是说,document.body.appendChild并没有什么特殊情况,依然与文档加载同步进行,加载到哪里便在哪处理。

ie全系列(此时最高为11)中有些无规律,也许是appendChild先执行,也许是文档中存在的先执行,但肯定是?2之后。

html文件

<div id="info"></div>
<script src="http://localhost:8083/-0test/test.js?1"></script>
<script src="http://localhost:8083/-0test/test.js?2"></script>
<p>一点内容</p>
<script>
var s = document.createElement('script');
s.src = 'http://localhost:8083/-0test/test.js?5';
document.body.appendChild(s);
var s = document.createElement('script');
s.src = 'http://localhost:8083/-0test/test.js?6';
document.body.appendChild(s);
</script>
<script src="http://localhost:8083/-0test/test.js?3"></script>
<script src="http://localhost:8083/-0test/test.js?4"></script>
<script src="http://localhost:8083/-0test/test.js?7"></script>
<p>一点内容2</p>

test.js文件 同上

输出

http://localhost:8083/-0test/test.js?1
http://localhost:8083/-0test/test.js?2
一点内容
http://localhost:8083/-0test/test.js?3
http://localhost:8083/-0test/test.js?4
http://localhost:8083/-0test/test.js?7
一点内容2
http://localhost:8083/-0test/test.js?7
http://localhost:8083/-0test/test.js?7

多个相同script引用探索的更多相关文章

  1. .Net Core 项目中的包引用探索(使用VSCode)

    本文组织有点乱,先说结论吧: 1 在 project.json 文件中声明包引用. 而不是像以前那样可以直接引用 dll. 2 使用 dotnet restore 命令后,nuget 会把声明的依赖项 ...

  2. 脚本引用中的defer和async的用法和区别

    之前的博客漫谈前端优化中的引用资源优化曾经提到过脚本引用异步设置defer.async,没有细说,这里展开一下,谈谈它们的作用和区别,先上张图来个针对没用过的小伙伴有个初始印象: 是的,就是在页面脚本 ...

  3. Bootstrap引用

    <!--设置移动设置页面标准-->        <meta name="viewport" content="width=device-width,i ...

  4. MVC模式下My97DatePicker日期控件引用注意事项

    My97DatePicker日期控件之前在用webform模式开发的时候,只要 <script language="javascript" type="text/j ...

  5. javascript学习笔记(一):基础、输出、注释、引用、变量、数据类型

    javascript脚本必须位于<script></script>之间,<script>标签可以位于<head>中,也可以位于<body>中 ...

  6. ASP.NET中母版页引用外部js或css文件无效,提示对象未定义解决方法

    最近做网站用了一个js+css实现的带有二级菜单的导航条,在母版页创建好后,子页面调用出现了许多奇怪的问题,多方查证后的最终解决方案和大家分享下.... 1.路径问题 如果是一个单独的aspx页面调用 ...

  7. js script type 部分属性值分析

    1. text/javascript: (1)<script type="text/javascript" src="Js/jquery-1.10.2.min.js ...

  8. vue 引用其他组件

    1.在components 目录下新建Test.vue 文件 <template> <div class="test"> <h1>{{ msg ...

  9. vue 不用npm下载安装包 该如何引用js

    公司电脑不让用npm  ,vue的项目要使用moment.js, 用了各种script 引用,总是报错 正确的方式应该为: import {moment} from ‘moment.js ’ 不可以全 ...

随机推荐

  1. Dojo系列教程

    Dojo学习笔记一: 认识Dojo http://blog.csdn.net/lfsfxy9/article/details/8623897 <dojo 边学边用> http://www. ...

  2. HTML5 修改浏览器url而不刷新页面

    嘛,起因是黑子大叔在微博上的一条@信息,找起了这个的实现,看了一圈google的中文信息内似乎还没有怎么提到这个的内容,就发表上来. 详细效果就是类似于用Firefox4+/Chrome 5+/Saf ...

  3. [ES6] 13. Using the ES6 spread operator ...

    The spread operator (...) allows you to "explode" an array into its individual elements. S ...

  4. MySQL中内存分为全局内存和线程内存

    首先我们来看一个公式,MySQL中内存分为全局内存和线程内存两大部分(其实并不全部,只是影响比较大的 部分): 复制代码 代码如下: per_thread_buffers=(read_buffer_s ...

  5. centos 服务器配置(三) 之定时任务

    有些liunx系统已经自带定时任务crontab,但是有的新装系统还未安装定时任务,这个时候就需要我们手动对其进行安装. 安装crontab: yum install crontabs 说明: /sb ...

  6. 15+ tar command usages with examples – Unix/Linux--reference

    reference :http://crybit.com/tar-command-usages-with-examples/ The ‘tar’ saves many files together i ...

  7. LINUX ping 指定网卡

    计算机上有多块网卡(例如笔记本电脑的无线网卡和以太网卡)连接至网络,使用ping命令想指定使用哪块网卡怎么办? ping -I eth0 10.10.10.1ping -I eth1 10.10.10 ...

  8. iOS获取设备型号

    导入头文件 #include <sys/types.h> #include <sys/sysctl.h> 直接调用 //获得设备型号 + (NSString *)getCurr ...

  9. 要检测两个C文件的代码的抄袭情况

    将抄袭部分输出 如果只是变量名替换了 也算抄袭 如果输入了一些干扰代码以防止被检测出来 也算抄袭专业程序代写c++程序代写

  10. 重构8-Replace Inheritance with Delegation(委托替换继承)

    继承的误用十分普遍.它只能用于逻辑环境,但却经常用于简化,这导致复杂的没有意义的继承层次.看下面的代码: public class Sanitation{ public String WashHand ...