Skip to content
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

Cannot require CSS from a partial. #198

Closed
HGCollier opened this issue Jul 19, 2023 · 1 comment
Closed

Cannot require CSS from a partial. #198

HGCollier opened this issue Jul 19, 2023 · 1 comment

Comments

@HGCollier
Copy link

This could just be me not understanding how the library works, but I have been unable to find any information in regards to rendering CSS from a partial. For example:

<head>
    @await Smidge.CssHereAsync(debug: true)
</head>
<body>
    <header>
        @await Html.PartialAsync("Navigation")
    </header>
</body>

In this instance, I have Smidge.RequiresCss("/lib/example/example.min.css") in the Navigation partial, which does not get rendered. If I put @await Smidge.CssHereAsync(debug: true) below where this partial is being rendered, it works fine.

Please could anyone advise me on how I can get CSS from my partials to render in the head of my HTML document/if this is possible?

@Shazwazza
Copy link
Owner

You cannot require assets in a partial. This is a common question but you can a conversation about that here #145 (comment)

To recap:

Creating dynamic bundles in partial views is problematic for various reasons:

  • If any partial view is cached, it breaks
  • If you want to use progressive rendering, it breaks
  • If you use child actions or view components, it breaks (generally speaking)
  • Depending on how you have structured your views, it may not work because the ordering of when partial views are executed isn't always the same. Razor generally renders things from the inside out but in .NET Core I don't think this is always the case especially since progressive rendering is possible

My advice is to create pre-defined bundles.

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

No branches or pull requests

2 participants