var total = 0;var receivedLength = 0;Blazor.start({ // start manually with loadBootResourceloadBootResource: function (type, name, defaultUri, integrity) {if (type == "dotnetjs")return defaultUri;if (location.hostname !== 'localhost')defaultUri = defaultUri + '.br';const fetchResources = fetch(defaultUri, { cache: 'no-cache' });return fetchResources.then(async (r) => {const reader = r.body.getReader();let length = +r.headers.get('Content-Length');total += length;var progressbar = document.getElementById('progressBar');let dataLength = 0;let dataArray = [];while (true) {const { done, value } = await reader.read();if (done) {break;}dataArray.push(value);dataLength += value.length;receivedLength += value.length;const percent = Math.round(receivedLength / total * 100)var pct = percent + '%';progressbar.style.width = pct;progressbar.innerText = pct + ' ' + calcSize(receivedLength) + '/' + calcSize(total);console.log('Received: ' + name + ',' + calcSize(dataLength) + '/' + calcSize(length));}let data = https://www.huyubaike.com/biancheng/new Uint8Array(dataLength);let position = 0;for (let array of dataArray) {data.set(array, position);position += array.length;}const contentType = type ==='dotnetwasm' ? 'application/wasm' : 'application/octet-stream';if (location.hostname !== 'localhost') {const decompressedResponseArray = BrotliDecode(data);return new Response(decompressedResponseArray,{ headers: { 'content-type': contentType } });}elsereturn new Response(data,{ headers: { 'content-type': contentType } });});return fetchResources;}});function calcSize(bytes) {if (bytes > 1024 * 1024) {return Math.round(bytes / 1024 / 1024 * 100) / 100 + 'MB';}else if (bytes > 1024) {return Math.round(bytes / 1024 * 100) / 100 + 'KB';}else {return bytes + 'B';}}
文章插图
这样加载内容就能缩小至2.5MB
效果
文章插图
链接最终效果,点击访问Github源码地址,点击访问
推荐阅读
- 如何破解压缩包的密码从网盘里面下载了一个压缩包,解压的时候需要输入密码,不知道密码是什么,该怎么
- 一 我要涨知识 —— TypeScript 常见面试题
- 克妻的男人面相特点有哪些,这4类男人千万不要嫁
- e笔画怎么写-E的正确笔顺怎么写?
- DNF怎么打红字(dnf武器有必要打红字么)
- 原神珊瑚宫心海突破材料需要哪些
- 原神钟离突破材料需要哪些
- 设计得什么填词语|设计写出搭配合适的词语
- 想开发DAYU200,我教你
- 这是你需要的初级钢琴教程汇总 练习曲篇