原理

使用可见性以及预取数据,同时充分利用浏览器的空闲时间,主要是解析href 以通过代码的选项指定需要加载的数据,当然其中
也添加了好多灵活的控制参数,方便我们使用,而且代码很小,压缩之后也就1kb

运行使用了docker

version: "3"
services:
web:
image: nginx
volumes:
- "./:/usr/share/nginx/html/"
ports:
- "8080:80"

基本使用

  • 基本代码结构
<!DOCTYPE html>
<html lang="en"> <head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script src="https://polyfill.io/v2/polyfill.min.js?features=IntersectionObserver"></script>
</head> <body>
<div class="h-c-header__initiative-logo h-c-header__initiative-logo--no-margin">
<a href="2.html" data-analytics='{
"category": "navigation",
"action": "header",
"label": "navlink: home"
}'
class="h-c-header__initiative-logo-link uni-click-tracker">
<span class="h-c-header__initiative-logo-text"> The Keyword</span>
</a>
</div>
<a href="static/js/login.js"></a>
<div id="landing-components" data-scripts='[
{ "url": "4.js",
"options": {
"async": true,
"defer": true
}
},
{ "url": "static/js/login.js",
"options": {
"async": true,
"defer": true
}
}
]'></div> <div id="userlogin"></div>
<input type="button" value="click load" onclick="load()" />
<iframe id="myhtml">
default content
</iframe>
<script type="text/javascript">
var scripts = document.querySelector("#landing-components").getAttribute('data-scripts');
scripts = JSON.parse(scripts);
scripts.forEach(function (scriptObj) {
var s = document.createElement('script');
s.async = scriptObj.options.async;
s.defer = scriptObj.options.defer;
s.src = scriptObj.url;
document.head.appendChild(s);
});
</script>
<script src="https://unpkg.com/quicklink@1.0.0/dist/quicklink.umd.js"></script> <script>
window.addEventListener('load', function () {
quicklink({});
}); function load() {
var content = document.getElementById("myhtml")
content.src = "2.html"
}
</script>
</body> </html>

效果测试

通过chrome 的调试可以看出数据已经进行加载了

参考资料

https://github.com/rongfengliang/quicklink-learning
https://github.com/GoogleChromeLabs/quicklink
https://github.com/w3c/IntersectionObserver

 
 
 
 

quicklink 基本使用的更多相关文章

  1. UWP学习记录12-应用到应用的通信

    UWP学习记录12-应用到应用的通信 1.应用间通信 “共享”合约是用户可以在应用之间快速交换数据的一种方式. 例如,用户可能希望使用社交网络应用与其好友共享网页,或者将链接保存在笔记应用中以供日后参 ...

  2. Axure RP介绍

    1.什么是原型设计?产品原型设计(Prototype Design)最基础的工作,就是结合批注.大量的说明以及流程图画框架图WireFrame,将自己的产品原型完整而准确的表述给 UI.UE.程序工程 ...

  3. 重新想象 Windows 8 Store Apps (39) - 契约: Share Contract

    [源码下载] 重新想象 Windows 8 Store Apps (39) - 契约: Share Contract 作者:webabcd 介绍重新想象 Windows 8 Store Apps 之  ...

  4. WP7:模拟开始屏幕Tile漂动效果

    在WP7手机的开始屏幕,如果你Hold住某一个瓷贴,就会发现除了你按住的那个瓷贴其他全部下沉半透明,然后开始在不停地漂来漂去~~今天来模仿一下这个效果.新建一个项目,然后在Grid里放一个ListBo ...

  5. 快速构建Windows 8风格应用15-ShareContract构建

    原文:快速构建Windows 8风格应用15-ShareContract构建 本篇博文主要介绍共享数据包.如何构建共享源.如何构建共享目标.DataTransferManager类. 共享数据包 Da ...

  6. win10 uwp App-to-app communication 应用通信

    这篇文章都是乱说的,如果觉得有不好的,可以发我邮箱 应用之间需要相互的发送信息,就是我们经常用的分享 有个人看到一个网页很好,于是就希望把这个网页发送到邮件,那么这样的话就是使用应用通信. 因为每个应 ...

  7. Axure RP 介绍

    原型设计是将想法转变为设计过程中至关重要的一环.经常有设计师小伙伴可能会问到,“哪个原型设计工具是最好的呢”?实际上这是一种错误的提问方式,尤其是在当下原型工具种类繁多,针对不同需求各有优势的大环境中 ...

  8. 背水一战 Windows 10 (100) - 应用间通信: 分享

    [源码下载] 背水一战 Windows 10 (100) - 应用间通信: 分享 作者:webabcd 介绍背水一战 Windows 10 之 应用间通信 分享 示例1.本例用于演示如何开发一个分享的 ...

  9. centos installation of matlab R2015b

    the source of installation is in the website: http://blog.csdn.net/hejunqing14/article/details/50265 ...

随机推荐

  1. XML(二)

    XML XML介绍 1.什么是xml? 概念:XML(EXtensible Markup Language)XML 指可扩展标记语言(EXtensible Markup Language) 可扩展:我 ...

  2. (C/C++学习笔记) 二. 数据类型

    二. 数据类型 ● 数据类型和sizeof关键字(也是一个操作符) ※ 在现代半导体存储器中, 例如在随机存取存储器或闪存中, 位(bit)的两个值可以由存储电容器的两个层级的电荷表示(In mode ...

  3. springboot 打包部署

    springboot内置有tomcat所以我们测试的时候没有加入自己的容器 那么我们的 springboot 怎么发布呢? 1.打成 jar 2.打成 war 这种方式我就不说了,网上有教程,我觉得j ...

  4. React 高阶组价详解

    这个教程还是不错的...

  5. nginx的相关配置记录和总结

    前言 本文旨在对nginx的各项配置文件和参数做一个记录和总结. 原因是在配置框架和虚拟目录,web语言解析的nginx环境的时候遇到各种问题和参数,有时百度可以解决,有时直接复制粘贴,大都当时有些记 ...

  6. WCF 添加服务引用 HTTP 请求已超过为 00:00:00 分配的超时。为此操作分配的时间可能是较长超时

    今天在用公司的笔记本引用WCF的时候,处于一直等待的过程,一直在下载信息,一直等了很长时间,弹出了一个消息 下载“http://ip:8085/xxxxx/xxxxx/mex/$metadata”时出 ...

  7. 检查服务器主从状态的脚本-check_server_state.sh

    分别检查服务器在Master/Slave状态下,各项服务是否正常,否则报警: 原来使用keepalived每隔1分钟调用,由于执行结果对keepalived的weight参数有影响,所以移动到外部,使 ...

  8. Mysql/Mariadb配置日志

    1. 创建日志存放目录: mkdir /var/log/mysql && chown mysql:mysql /var/log/mysql 2.修改Mysql配置日志: vi /etc ...

  9. go:基于时间轮定时器方案

    /* * http://blog.csdn.net/yueguanghaidao/article/details/46290539 * 修改内容:为定时器增加类型和参数属性,修改回调函数类型 */ p ...

  10. ZOJ 1006:Do the Untwist(模拟)

    Do the Untwist Time Limit: 2 Seconds      Memory Limit: 65536 KB Cryptography deals with methods of ...