Skip to content

Conversation

@guardrex
Copy link
Collaborator

@guardrex guardrex commented Jan 15, 2026

Fixes #36628

Marek ... I might be incorrect, but it seems like the example that you were referring to is correct by design because it states the module is using the .js file extension ...

... a module named scripts.js in the app's wwwroot/js folder is fingerprinted by adding #[.{fingerprint}] before the file extension (.js):

... and then it goes on to say that if the dev wants to fingerprint .mjs files, they use StaticWebAssetFingerprintPattern.

We are adding StaticWebAssetFingerprintPattern with .mjs

Yes, but that's after the example of a .js module IF they want to use a different extension (or fingerprint expression). Perhaps, I can fix that lead-in line and make it more specific like this ...

To fingerprint additional JS modules with a different file extension or fingerprint expression in standalone Blazor WebAssembly apps, use the <StaticWebAssetFingerprintPattern> property in the app's project file (.csproj).

... which is on this PR.

However, I might be misunderstanding the feature/problem with what's in the article.

@maraf
Copy link
Member

maraf commented Jan 16, 2026

The twist is .js files are not fingerprinted by default, because we don't know if they will be loaded as modules as by other mechanism. We can fingeprint .js files only if they are modules and thus browser will apply importmap when resolving the URL.

@guardrex
Copy link
Collaborator Author

guardrex commented Jan 16, 2026

The behavior doesn't seem to match that. What am I missing in the following scenario? .........

If I create a plain (non-module) JS script (wwwroot/script.js) with a JS FN in it ...

function alertMessage() {
  alert("Hello from JavaScript!");
}

... and I add the fingerprint expression to its filename ...

<script src="script#[.{fingerprint}].js"></script>

It gets fingerprinted and placed into the import map ...

image image

@maraf
Copy link
Member

maraf commented Jan 16, 2026

Does it work on publish output?

@guardrex
Copy link
Collaborator Author

Not sure ... I didn't test. I'll check that and see what happens. brb

@guardrex
Copy link
Collaborator Author

guardrex commented Jan 16, 2026

I see what you mean ... no ... it doesn't fingerprint that file after the app is published. I'm not sure if I was just being silly expecting it to work like that.

Anyway ... for the changes that we need here, let me try another pass on this to see if I can get the coverage right. I'm still a bit confused tho because .js files could be modules or not modules. Does the framework figure that out ... and then if the .js file is a module, it will do the fingerprinting?

Rubber 🦆 says 'no' to that. I just tried with type="module", and it doesn't fingerprint on publish.

@guardrex
Copy link
Collaborator Author

guardrex commented Jan 16, 2026

I'm attempting to understand this feature better, and I tried the MSBuild config for .mjs, but I get ...

The attribute "Include" in element <StaticWebAssetFingerprintPattern> is unrecognized. The project file is invalid on disk and was not reloaded.

Any idea what might be going wrong?

@guardrex
Copy link
Collaborator Author

guardrex commented Jan 16, 2026

Ah .... rubber 🦆 says, 'that's an <ItemGroup> you silly 🦖!' 🙈😆 ... We better add that to the coverage.

@guardrex
Copy link
Collaborator Author

guardrex commented Jan 16, 2026

@maraf ... Ok, I think 🤔 that I'm getting this feature now. See if the diff (I made two commits) covers what we need to say.

If so, I'll go into the reference article coverage next and make similar updates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tweaks to .NET 10.0 release notes for Blazor

3 participants