Request *.wasm.gz files from Blazor WASM Bootstrapper #66161
Replies: 1 comment
-
|
yeah you re right - the default bootstrapper doesn t ask for .gz files on its own. but it s easy to fix. you just override the loadBootResource function in your index.html basically you intercept how the files load and add .gz to the end of the URL. that way the browser requests the compressed file directly and cloudflare s size limit won t be a problem anymore here s a quick example: <script src="_framework/blazor.webassembly.js" autostart="false"></script>
<script>
Blazor.start({
loadBootResource: function (type, name, defaultUri, integrity) {
if (type === 'dotnetjs' || type === 'dotnetwasm' || type === 'assembly') {
return `${defaultUri}.gz`;
}
}
});
</script>one thing though -your server needs to serve those .gz files with the right headers: and don t worry about decompression. the browser handles that automatically as long as the Content-Encoding: gzip header is there. it unzips the file before passing it to Blazor so no extra code needed if my answer was helpful please mark it as such so that others can benefit from it as well. i hope this helps you resolve your cloudflare issue.... |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I noticed *.wasm.gz versions of files is generated during compile/publish.
Is there a way to configure Blazor WASM bootstrapper to request *.wasm.gz version of files directly during loading? I.e. such that the URL of the request would include the *.gz
This would be useful where a static file host limits the size of files if the .*.wasm file is too large. I encountered this with the cloudflare plan in one instance.
I could not determine a way to host only the .wasm.gz file but have the CDN respond to /.wasm URL's and implicitly serve the *.gz with compression header.
I know this is kind of a host specific issue, but if the runtime loader can just be configured to request *.wasm.gz directly then the host's limitation becomes a non-issue. Maybe this isn't feasible of the bootstrapper doesn't have a way to un-gzip the file without the browser handling it implicitly?
Beta Was this translation helpful? Give feedback.
All reactions