LayerZero.Tools.Web 1.3.0

dotnet add package LayerZero.Tools.Web --version 1.3.0
                    
NuGet\Install-Package LayerZero.Tools.Web -Version 1.3.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="LayerZero.Tools.Web" Version="1.3.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="LayerZero.Tools.Web" Version="1.3.0" />
                    
Directory.Packages.props
<PackageReference Include="LayerZero.Tools.Web" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add LayerZero.Tools.Web --version 1.3.0
                    
#r "nuget: LayerZero.Tools.Web, 1.3.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package LayerZero.Tools.Web@1.3.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=LayerZero.Tools.Web&version=1.3.0
                    
Install as a Cake Addin
#tool nuget:?package=LayerZero.Tools.Web&version=1.3.0
                    
Install as a Cake Tool

πŸ“¦ Dynamic Bundle Loader for ASP.NET Core

NuGet NuGet Downloads .NET


A convention-based asset bundling system for .NET 8+ using WebOptimizer. Automatically discovers and injects CSS/JS bundles per controller and action using Razor TagHelpers.

🧩 Not a full framework.
❌ Doesn’t replace WebOptimizer.
βœ… Enhances it with dynamic discovery, layout scoping, and critical asset control.


πŸ” Purpose

Eliminates manual asset management in Razor views by scanning controller/action folder structures and auto-generating optimized bundles at runtime.


πŸ—‚ Folder Convention

wwwroot/
|   
+---css
|   |   site.css
|   |   
|   +---Controller
|   |   \---Home
|   |       |   Home.css
|   |       |   
|   |       +---Index
|   |       |       StyleSheet.css
|   |       |       
|   |       \---Privacy
|   |               StyleSheet.css
|   |               
|   \---critical
|           StyleSheet-cr1.css
|           StyleSheet-cr2.css
|           
+---js
|   |   site.js
|   |   
|   +---Controller
|   |   \---Home
|   |       |   Script.js
|   |       |   
|   |       +---Index
|   |       |       Script.js
|   |       |       
|   |       \---Privacy
|   |               flickity.pkgd.min.js
|   |               JavaScript.js
|   |               
|   \---critical
|           JavaScript-cr1.js
|           JavaScript-cr2.js
|           
\---lib

  • Controller/Action structure drives bundle discovery.
  • A special folder for critical CSS (wwwroot/css/critical)
  • A special folder for critical JS (wwwroot/js/critical)

βš™οΈ Installation

1. Add the NuGet Package

dotnet add package LayerZero.Tools.Web

Or reference the project directly:

dotnet new classlib -n LayerZero.Tools.Web
dotnet add reference ../LayerZero.Tools.Web/LayerZero.Tools.Web.csproj

2. NuGet Dependencies

<PackageReference Include="LigerShark.WebOptimizer.Core" Version="3.0.456" />
<PackageReference Include="LigerShark.WebOptimizer.Core" Version="3.0.456" />
<FrameworkReference Include="LayerZero.Tools" Version="1.0.1"/>

πŸš€ Usage

Register in Program.cs

builder.Services.AddDynamicBundle();

Or if you want to enable cache-busting on dev environment:

builder.Services.AddDynamicBundle(builder.Environment);

Enable Middleware

app.UseWebOptimizer();

🧠 TagHelpers

Register in _ViewImports.cshtml

@addTagHelper *, LayerZero.Tools.Web

Use in _Layout.cshtml

<head>
    <critical-style-bundle-loader/>
    <style-bundle-loader />
</head>
<body>
    @RenderBody()
    <critical-script-bundle-loader/>
    <script-bundle-loader />
</body>

Controller-wide assets load by default and are overridden by action-specific bundles if found.


πŸ’‘ Features

βœ… Convention-over-configuration
βœ… Minification only in production
βœ… Controller & action bundle granularity
βœ… TagHelpers for clean layout injection
βœ… Auto-registers bundles at startup
βœ… Inline critical CSS
βœ… Inline critical JS
βœ… Cache-busting in development mode


⚠️ Known Limitations

  • ❌ Custom asset folder paths are not configurable via AddDynamicBundle() same as v1.1.0.
  • ❌ Dynamic runtime configuration of asset logic is not exposed yet.
  • βœ… A static convention-based pathing system is in place (e.g., wwwroot/css/Controller/Action/...).

These constraints persist in v1.2.0 and will be addressed in v2.0.0.


πŸ”₯ Critical CSS (v1.1.0+)

  • Combines all .css files under wwwroot/css/critical/ into a single <style> tag.
  • Injected above all other stylesheets.

πŸ”₯ Critical JS (v1.2.0+)

  • Combines all .js files under wwwroot/js/critical/ into one <script> tag.
  • Injected before all other scripts for optimal early execution.
  • In v1.2.0, scripts are injected as-is β€” no syntax validation or dependency analysis is performed yet.

πŸ†• What's New in v1.3.0

LayerZero.Tools.Web now includes Critical JavaScript support:

  • Place scripts in wwwroot/js/critical/
  • Files are parsed and rendered inline, before all standard JS bundles
  • Useful for early execution logic such as feature flags, layout adjustments, or performance-critical bootstraps

Critical JS handling mirrors Critical CSS introduced in v1.2.0, forming a complete early asset delivery strategy.


🚫 Cache-Busting in Development

To prevent browser caching during local testing, development mode appends ?v=<random> to asset URLs.

<link rel="stylesheet" href="/bundles/home.min.css?v=46174bc4-f61a-4382-a733-81ffe8c73074" />

In production, clean URLs are used for optimal caching.


✨ Example

Requesting /Home/Index loads:

<style>/* critical CSS injected here */</style>
<link rel="stylesheet" href="/bundles/home.min.css" />
<link rel="stylesheet" href="/bundles/home/index.min.css" />
<script>/* critical JS injected here */</script>
<script src="/bundles/home.min.js"></script>
<script src="/bundles/home/index.min.js"></script>

πŸ›£ Planned for v2.0.0

A new configuration object will be introduced to allow:

  • βœ… Custom JsRoot, CssRoot, CriticalCssRoot directories.
  • βœ… Optional feature toggles for minification, cache-busting, critical asset control.
  • βœ… Fluent configuration syntax.
builder.Services.AddDynamicBundle(new DynamicBundleConfig
{
    JsRoot = "wwwroot/assets/js",
    CssRoot = "wwwroot/assets/css",
    CriticalCssRoot = "wwwroot/assets/critical",
    EnableCacheBusting = true
});

πŸ‘€ Author

LayerZero Team β€” Built for clean architecture and developer clarity.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.3.0 81 7/5/2025
1.2.0 70 6/28/2025
1.1.1 110 6/22/2025
1.1.0 106 6/22/2025
1.0.1 195 6/13/2025
1.0.0 290 6/11/2025