dotnet / dotnet/aspnetcore

Make dotnet.js and dotnet.boot.js import more EASY IN WEB WORKER

Open
#66,065 3 comments 0 reactions 1 assignee Claimed by @ilonatommy View on GitHub
area-blazor
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 5h
Merged PRs (30d)
276

Description

### Is there an existing issue for this?

- [x] I have searched the existing issues

### Is your feature request related to a problem? Please describe the problem.

**Currently the **#[.{fingerprint}]** replacing only works for index.html. It makes dotnet.js and dotnet.boot.js import very difficult in webworker and need to write a lot urgly codes.**

### Describe the solution you'd like

**If the build or publish flow can replace all import path for all js or html files, it would be great for our developers!**

### Additional context

**Workarround:**
[QRGenerator.razor.js](https://github.com/user-attachments/files/26331934/QRGenerator.razor.js)
[QRGeneratorClient.razor.js](https://github.com/user-attachments/files/26331935/QRGeneratorClient.razor.js)

**Use post message to init:**
```
let dotnetJsUrl = '../_framework/dotnet.js';
let dotnetBootJsUrl = '../_framework/dotnet.boot.js';
await sendRequestToWorker({ command: 'init', dotnetJsUrl: import.meta.resolve?.(dotnetJsUrl) ?? dotnetJsUrl, dotnetBootJsUrl: import.meta.resolve?.(dotnetBootJsUrl) ?? dotnetBootJsUrl });
```
```

switch (command) {
case 'init':
try {
let dotnetJsUrl = e.data.dotnetJsUrl;
let dotnetBootJsUrl = e.data.dotnetBootJsUrl;
console.log(`Initializing worker with dotnet.js: ${dotnetJsUrl}, dotnet.boot.js: ${dotnetBootJsUrl}`, );
if (!dotnetJsUrl) {
console.warn('dotnetJsUrl not provided, using default path');
dotnetJsUrl = '../_framework/dotnet.js';
}
const { dotnet } = await import(dotnetJsUrl);
const { getAssemblyExports, getConfig } = dotnetBootJsUrl ? await dotnet.withConfigSrc(dotnetBootJsUrl).create() : await dotnet.create();
const config = getConfig();
assemblyExports = await getAssemblyExports(config.mainAssemblyName);
console.log('Worker initialized successfully');
} catch (err) {
startupError = err.message;
}
result = true;
break;
case 'generateQR':
result = assemblyExports.QRGenerator.Generate(e.data.text, e.data.size);
break;
default:
throw new Error(`Unknown command: ${command}`);
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.