This project restores the RuntimeMinifier functionality to Umbraco v16.1.1+, powered by Smidge. The RuntimeMinifier was removed in Umbraco v14, and this package reintroduces it for developers who need runtime minification of CSS and JavaScript assets.
- Runtime minification of CSS and JavaScript using Smidge
- Easy integration with Umbraco v16.1.1+
- Configuration options for bundling and cache busting
- Add the NuGet package to your Umbraco project:
dotnet add package Umbraco.Community.Smidge
- Ensure your project is running Umbraco v16.1.1 or later.
-
Add
.AddRuntimeMinifier()to your UmbracoBuilder:// In your Startup or Program.cs builder.CreateUmbracoBuilder() .AddBackOffice() .AddWebsite() .AddComposers() .AddSlimsy() .AddRuntimeMinifier() .Build();
-
Use the
IRuntimeMinifierinterface to minify assets at runtime.
// Example usage in a notification handler
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Events;
using Umbraco.Cms.Core.Notifications;
using Umbraco.Cms.Core.Services;
using Umbraco.Community.Smidge;
public class CreateBundlesNotificationHandler : INotificationHandler<UmbracoApplicationStartingNotification>
{
private readonly IRuntimeMinifier _runtimeMinifier;
private readonly IRuntimeState _runtimeState;
public CreateBundlesNotificationHandler(IRuntimeMinifier runtimeMinifier, IRuntimeState runtimeState)
{
_runtimeMinifier = runtimeMinifier;
_runtimeState = runtimeState;
}
public void Handle(UmbracoApplicationStartingNotification notification)
{
if (_runtimeState.Level == RuntimeLevel.Run)
{
_runtimeMinifier.CreateJsBundle("core-javascript-bundle",
BundlingOptions.OptimizedNotComposite,
["~/scripts/main.min.js"]);
_runtimeMinifier.CreateCssBundle("core-style-bundle",
BundlingOptions.OptimizedNotComposite,
["~/css/bootstrap.min.css", "~/css/main.min.css"]);
}
}
}- You can customize bundling and cache busting via the provided options classes (
BundlingOptions,RuntimeMinificationSettings, etc.). - Refer to the source files for advanced configuration.
Contributions are welcome! Please submit issues or pull requests via GitHub.
This project is licensed under the MIT License. See the LICENSE file for details.
- Smidge by Shannon Deminick
- Umbraco Community
For more information, see the source code and comments in this repository.