Skip to content

Commit a8961c0

Browse files
Fetch Brotli-precompressed framework files
1 parent 6f73ce4 commit a8961c0

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

wwwroot/decode.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

wwwroot/index.html

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,24 @@
5050
<a href="" class="reload">Reload</a>
5151
<a class="dismiss">🗙</a>
5252
</div>
53-
53+
<script src="decode.js"></script>
5454
<script src="_framework/blazor.webassembly.js" autostart="false"></script>
5555
<script>
5656
Blazor.start({
5757
loadBootResource: function (type, name, defaultUri, integrity) {
58-
// For framework resources, use the precompressed .gz files for faster downloads
59-
// This is needed only because GitHub pages doesn't natively support response compression for .dll files
60-
if (type === 'assembly') {
58+
// For framework resources, use the precompressed .br files for faster downloads
59+
// This is needed only because GitHub pages doesn't natively support Brotli (or even gzip for .dll files)
60+
if (type !== 'dotnetjs' && location.hostname !== 'localhost') {
6161
return (async function () {
62-
const response = await fetch(defaultUri + '.gz', { cache: 'no-cache' });
63-
const originalResponseBlob = await response.blob();
64-
const decompressedStream = originalResponseBlob.stream().pipeThrough(new DecompressionStream('gzip'));
65-
return new Response(decompressedStream, { headers: response.headers });
62+
const response = await fetch(defaultUri + '.br', { cache: 'no-cache' });
63+
if (!response.ok) {
64+
throw new Error(response.statusText);
65+
}
66+
const originalResponseBuffer = await response.arrayBuffer();
67+
const originalResponseArray = new Int8Array(originalResponseBuffer);
68+
const decompressedResponseArray = BrotliDecode(originalResponseArray);
69+
const contentType = type === 'dotnetwasm' ? 'application/wasm' : 'application/octet-stream';
70+
return new Response(decompressedResponseArray, { headers: { 'content-type': contentType } });
6671
})();
6772
}
6873
}

0 commit comments

Comments
 (0)