-
Notifications
You must be signed in to change notification settings - Fork 25.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add example for configuring JS collocation in _Layout.cshtml #33190
Conversation
Hello @sliekens ... It's a reasonable tip, but this would need to call out that every page of the layout must have a collocated JS file. @Rick-Anderson ... Are you interested in this? |
@guardrex I see why you might think that it always adds a script tag to every page, but |
I see. I looked it up, and it didn't say that was the case ... Rick manages that article, so he'll determine if any additional updates are in order. BTW Rick ... The INCLUDE file is no longer used for Blazor. Blazor now has a dedicated INCLUDE to cover special Blazor-y things. This INCLUDE is only used in the RP article now, so you could (or I could since I created this file in the first place) drop it and place the contents of the file into that one article where it appears. Let me know if you want me to do it after this PR is resolved. 👂 |
For context about why this works: <!-- <script asp-src-include="@(ViewContext.View.Path).js"></script> -->
<script asp-src-include="/Pages/Index.cshtml.js"></script> The ScriptTagHelper uses the string The ScriptTagHelper also deletes the original (Perhaps I need to update the PR with a note about this behavior?) |
Probably best to wait for Rick to see this. It seems harmless enough as a tip. Rick might want to document the underlying behavior in the Script Tag Helper article and cross-link to it from here. The cross-link will probably be to He'll be along in a few hours ... he's in a different time zone 🌔. |
@Rick-Anderson sorry, what's an RP sample? 😀 /edit: having just realized RP means Razor Pages, what are your expectations for such a sample? |
This advice should work for Razor pages and for MVC views. I'm not sure about scripts provided by Razor class libraries, I don't use them personally.
Co-authored-by: Rick Anderson <3605364+Rick-Anderson@users.noreply.github.com>
Sorry for using RP, I should have spelled it out. Just the simplest possible sample that demonstrates JS collocation in Start with the template generated RP project and add what's need to demonstrate the preceding. You can do the sample in another PR and add add closes |
Okay @Rick-Anderson I canceled the automerge because I had already pushed a part of the sample to this branch. I will move the changes over to a new PR. |
@sliekens sorry about that, merging here would have been fine. I didn't realize you could generate a sample that fast and didn't want to hold up this PR. Either way is fine. |
@Rick-Anderson if you could review again, I hope this is what you had in mind. |
Looks great. I'll test it tomorrow. |
Cool, thanks 😎👍 |
This advice should work for Razor pages and for MVC views. I'm not sure about scripts provided by Razor class libraries, I don't use them personally.
EDIT:
Document Details
⚠ Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.
Internal previews