DOM加载顺序

本文详细介绍了HTML文档的加载过程,包括HTML结构解析、外部资源加载与执行等内容。同时,深入探讨了JavaScript的加载及执行机制,帮助读者理解网页加载的全貌。
  1. 解析HTML结构。
  2. 加载外部脚本和样式表文件。
  3. 解析并执行脚本代码。
  4. 构造HTML DOM模型。
  5. 加载图片等外部文件。
  6. 页面加载完毕。
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Title</title>
    <style type="text/css">
        body
        {
            font-sie: 12px;
        }
    </style>
    <link href="style.css" rel="stylesheet" type="text/css" media="all" />
    <script src="js.js" type="text/javascript"></script>
</head>
<body>
    <div>
        <script type="text/javascript">
            function f1() { }
        </script>
        <img src="1.gif" />
    </div>
    <script type="text/javascript">
        function f2() { }
    </script>
</body>
</html>

 html → head → title → #text(网页标题) → style → 加载样式 → 解析样式 → link → 加载外部样式表文件 → 解析外部样式表 → script → 加载外部脚本文件 → 解析外部脚本文件 → 执行外部脚本 → body → div → script → 加载脚本 → 解析脚本 → 执行脚本 → img → script → 加载脚本 → 解析脚本 → 执行脚本 → 加载外部图像文件 → 页面初始化完毕

 

JS加载包含预编译和执行两个阶段。 编译阶段会对所有的var变量和function进行扫描,并将var变量初始化为undefined类型,而function则被初始化为函数值。

到了执行阶段,JS从上面往下面依顺序执行,遇到var变量便进行赋值(因此,在赋值之前进行调用的话会出现错误).遇到函数变量的话会从活动对象中寻找函数

 

javascript在html中的加载顺序 : http://www.cnblogs.com/CBDoctor/p/3745246.html

 

 

转载于:https://www.cnblogs.com/zhuiluoyu/p/5013875.html

### Vue.js 组件加载顺序与生命周期钩子执行顺序 在 Vue.js 中,组件的生命周期钩子函数按照特定的顺序执行,这种设计确保了组件的状态和行为能够按预期运行。以下是详细的生命周期钩子执行顺序: #### 1. **加载渲染过程** 当一个父组件及其子组件初次加载并挂载到 DOM 上时,其生命周期钩子的执行顺序如下: - 父 `beforeCreate`[^1] - 父 `created`[^1] - 父 `beforeMount` - 子 `beforeCreate`[^1] - 子 `created` - 子 `beforeMount`[^1] - 子 `mounted`[^1] - 父 `mounted` 此顺序表明,在初始渲染期间,父组件的初始化操作优先于子组件完成。 #### 2. **子组件更新过程** 当父组件的数据发生变化从而引发子组件重新渲染时,生命周期钩子的执行顺序为: - 父 `beforeUpdate`[^3] - 子 `beforeUpdate`[^3] - 子 `updated` - 父 `updated`[^3] 在此过程中,父组件负责通知子组件进行更新,而具体的更新逻辑由子组件自行处理。 #### 3. **父组件更新过程** 如果仅涉及父组件自身的状态变化而不影响子组件,则只有以下钩子会被调用: - 父 `beforeUpdate`[^3] - 父 `updated` 这一步骤展示了父组件独立更新的能力。 #### 4. **销毁过程** 当组件实例被移除或销毁时,生命周期钩子的执行顺序遵循自底向上的原则: - 父 `beforeDestroy` - 子 `beforeDestroy`[^3] - 子 `destroyed` - 父 `destroyed` 这一机制保证了子组件资源释放完毕后再清理父组件的相关依赖。 通过以上四个阶段的描述可以看出,Vue 的生命周期管理严格区分了不同场景下的职责划分,并提供了丰富的钩子供开发者灵活控制程序的行为。 ```javascript // 示例代码展示父子组件生命周期钩子打印日志 <template> <div id="app"> <ParentComponent /> </div> </template> <script> import ParentComponent from './components/ParentComponent.vue'; export default { name: 'App', components: { ParentComponent } }; </script> // ParentComponent.vue <template> <ChildComponent /> </template> <script> import ChildComponent from './ChildComponent.vue'; export default { name: 'ParentComponent', beforeCreate() { console.log('Parent -> beforeCreate'); }, created() { console.log('Parent -> created'); }, beforeMount() { console.log('Parent -> beforeMount'); }, mounted() { console.log('Parent -> mounted'); }, beforeUpdate() { console.log('Parent -> beforeUpdate'); }, updated() { console.log('Parent -> updated'); }, beforeDestroy() { console.log('Parent -> beforeDestroy'); }, destroyed() { console.log('Parent -> destroyed'); }, components: { ChildComponent } }; </script> // ChildComponent.vue <script> export default { name: 'ChildComponent', beforeCreate() { console.log('Child -> beforeCreate'); }, created() { console.log('Child -> created'); }, beforeMount() { console.log('Child -> beforeMount'); }, mounted() { console.log('Child -> mounted'); }, beforeUpdate() { console.log('Child -> beforeUpdate'); }, updated() { console.log('Child -> updated'); }, beforeDestroy() { console.log('Child -> beforeDestroy'); }, destroyed() { console.log('Child -> destroyed'); } }; </script> ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值