惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

SecWiki News
SecWiki News
I
InfoQ
The Cloudflare Blog
人人都是产品经理
人人都是产品经理
博客园 - Franky
T
Tailwind CSS Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
量子位
博客园_首页
罗磊的独立博客
V
V2EX
李成银的技术随笔
大猫的无限游戏
大猫的无限游戏
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
True Tiger Recordings
Vercel News
Vercel News
Cyberwarzone
Cyberwarzone
Cisco Talos Blog
Cisco Talos Blog
F
Fox-IT International blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
M
Microsoft Research Blog - Microsoft Research
Know Your Adversary
Know Your Adversary
爱范儿
爱范儿
The Register - Security
The Register - Security
G
Google Developers Blog
The Hacker News
The Hacker News
Malwarebytes
Malwarebytes
S
Securelist
博客园 - 三生石上(FineUI控件)
Jina AI
Jina AI
T
Threat Research - Cisco Blogs
T
The Exploit Database - CXSecurity.com
S
SegmentFault 最新的问题
博客园 - 叶小钗
F
Fortinet All Blogs
Apple Machine Learning Research
Apple Machine Learning Research
宝玉的分享
宝玉的分享
博客园 - 聂微东
T
Threatpost
博客园 - 【当耐特】
D
Docker
P
Privacy & Cybersecurity Law Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
G
GRAHAM CLULEY
V
Visual Studio Blog
C
Cisco Blogs
IT之家
IT之家
S
Security Archives - TechRepublic
Latest news
Latest news
阮一峰的网络日志
阮一峰的网络日志

Fgaoxing

MiniGFM:3KB的轻量Markdown渲染库 Go反射:性能瓶颈与零拷贝优化 至全体朋友 Goh:一款Go语言的预编译快速模板引擎。(Benchmark排名第一) 【预告】关于函数传参时栈的变化 【谈谈当下】青少年口中的垃圾话语 【LSP】微型滚动动画库 推一下 Vercel 加速节点 网站优化小窍门 【显微镜下的世界】0x1 【Hexo】优化教程 【CDNN】CDNN再添一员 懒加载的妙用:缓存篇 BiliBili崩了 【New Bing】New Bing免代理申请和使用 simplest-server Python实现文件查重 放开想,越离谱越好 2022 夏季应用推荐
【FastJump.js】简单的快速跳转技术
2023-03-17 · via Fgaoxing

110行写了个小玩意,可以像sw那样离线缓存,和Pjax类似,不过用了自主缓存,fetch做请求,算了上代码吧:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
self.CACHE_NAME = 'FastJumpCache'; 
self.db = {
read: (key) => {
return new Promise((resolve, reject) => {
caches.match(new Request(`https://LOCALCACHE/${encodeURIComponent(key)}`)).then(function (res) {
res.text().then(text => resolve(text));
}).catch(() => {
resolve(null);
});
})
}, write: (key, value) => {
return new Promise((resolve, reject) => {
caches.open(CACHE_NAME).then(function (cache) {
cache.put(new Request(`https://LOCALCACHE/${encodeURIComponent(key)}`), new Response(value));
resolve();
}).catch(() => {
reject();
});
});
}
}

document.addEventListener('DOMContentLoaded', function () {
self.db.read(window.location.href).then(function (d) {
if (!d) {
fetch(window.location.href).then(function (d) {
if (d.headers.get('content-type') === 'text/html') {
d.text().then(function (b) {
self.db.write(window.location.href, b)
})
}
})
}
});
});

document.addEventListener('DOMContentLoaded', function () {
setInterval(function () {
var doms = document.querySelectorAll('a[href]');
Array.prototype.forEach.call(doms, function (dom) {
if (dom.href && dom.href.indexOf(window.location.origin) === 0) {
dom.onclick = function () {
history.pushState({}, '', dom.href);
self.db.read(dom.href).then(function (d) {
if (d) {
console.clear();
document.open();
try {
document.write(d);
let Event_timerun = window.setInterval(function () {
if (document.body&&document.body.innerHTML) {
let Event = new CustomEvent('onload')
document.dispatchEvent(Event);
window.dispatchEvent(Event);
Event = new CustomEvent('DOMContentLoaded')
document.dispatchEvent(Event);
window.dispatchEvent(Event);
window.clearInterval(Event_timerun)
}
},500)
fetch(dom.href).then(function (d) {
if (d.headers.get('content-type') === 'text/html') {
d.text().then(function (b) {
self.db.write(window.location.href, b)
})
}
})
} catch (e) {

}
} else {
fetch(dom.href).then(function (d) {
if (d.headers.get('content-type') === 'text/html') {
d.text().then(function (b) {
console.clear();
document.open();
try {
document.write(b)
let Event_timerun = window.setInterval(function () {
if (document.body&&document.body.innerHTML) {
let Event = new CustomEvent('onload')
document.dispatchEvent(Event);
window.dispatchEvent(Event);
Event = new CustomEvent('DOMContentLoaded')
document.dispatchEvent(Event);
window.dispatchEvent(Event);
window.clearInterval(Event_timerun)
}
},500)
} catch (e) {
}
self.db.write(dom.href, b)
}).catch(function (e) {
window.location.href = dom.href
})
}
}).catch(function (e) {
window.location.href = dom.href
})
}
}).catch(function (e) {
window.location.href = dom.href
})
return false;
}
}
});
}, 500)
});

注意不能与Pjax一起使用!!
鄙人水平有限,请斧正
有不少Bug,仅供测试,不可以在线上环境使用