从CRP(关键渲染路径)优化中谈浏览器渲染原理

前言:

  1. 该文中涉及的一切问题,只在页面首次渲染条件下讨论,因后续产生的DOM和CSSOM的更新及布局绘制不在本文范围内;
  2. 本文参考Google的Critical Rendering Path部分,做了选择性的摘录,以及自己的思考和总结,若对原文感兴趣的可以点击前往。如有表述不当的地方,还请指出

1. CRP

CRP,即critical rendering path的缩写,中文译文关键渲染路径。具体是什么呢?

浏览器从收到 HTML、CSS 和 JavaScript 字节到对其进行必需的处理,从而将它们转变成渲染的像素这一过程中有一些中间步骤,这些必要的步骤,就是CRP。

注意:
CRP的起点发生在新页面,为从服务器获得HTML文件的那一刻;故以下几项和CRP没有半毛钱全系: 通过控制台添加节点、hover, active等使样式发生变化、用JS写成的交互性渲染操作之类的操作。
CRP的终点是完成浏览器内像素的渲染,但之后的工作不属于CRP: 例如 1. 不会对页面的初始渲染产生影响的js代码的运行;2. 与服务器进行的后续数据传输;3. 甚至不符合当前的媒体查询条件的CSS文件的加载(因为这些样式对当前来说是不起作用的,不符合“必需”要求);

问题来了,凭什么说例子中的几项不在CRP中,即:如何判别某一事项不会影响页面的初次渲染成像呢?那就需要谈及浏览器的渲染流程。

2. 浏览器的渲染原理

2.1 对象模型(OM)的构建

2.1.1 文档对象模型(DOM)

虽然家喻户晓,但还是说一下吧:

<html>
  <head>
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <link href="style.css" rel="stylesheet">
    <title>Critical Path</title>
  </head>
  <body>
    <p>Hello <span>web performance</span> students!</p>
    <div><img src="awesome-photo.jpg"></
  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
# CRP Open source C++ Implementation of Customizable Route Planning (CRP) by Delling et al. This project was part of a practical course at Karlsruhe Institute of Technology (KIT). Requirements ============ In order to build CRP you need to have the following software installed: - Boost C++ Library (http://www.boost.org), more specifically Boost Iostreams. - Scons (http://scons.org) - g++ >= 4.8 (https://gcc.gnu.org) Building CRP ============ If the Boost Library is not in your PATH, make sure to edit the *SConstruct* file in the root directory to point the build script to the correct location of Boost. There is a section *Libraries* in the *SConstruct* file where you can specify the paths. Once you have installed all the software packages listed above, you can build the CRP programs by typing ``` scons --target=CRP --optimize=Opt -jX ``` into your terminal where `X` is the number of cores you want to use for building the project. If you want to use a specific g++ compiler version you can add `--compiler=g++-Version`. We also support a debug and profiling build that you can call with `--optimize=Dbg` and `--optimize=Pro` respectively. This command will build three programs in the folder *deploy*: - *osmparser*: Used to parse an OpenStreetMap (OSM) bz2-compressed map file. Call it with `./deploy/osmparser path_to_osm.bz2 path_to_output.graph.bz2` - *precalculation*: Used to build an overlay graph based on a given partition. Call it with `./deploy/precalculation path_to_graph path_to_mlp output_directory`. Here, *path_to_mlp* is the path to a *MultiLevelPartition* file for the graph that you need to provide. For more details, take a look into our project documentation. - *customization*: Used to precompute the metric weights for the overlay graph. Call it with `./deploy/customization path_to_graph path_to_overlay_graph metric_output_directory metric_type`. We currently support the following metric types: *hop* (number of edges traversed), *time* and *dist*.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值