https://github.com/ogaudefroy/dynamicstylebundles
A lightweight library which simplifies dynamic assets bundling via System.Web.Optimization
https://github.com/ogaudefroy/dynamicstylebundles
asp-net bundling multitenant white-label-sites
Last synced: 7 months ago
JSON representation
A lightweight library which simplifies dynamic assets bundling via System.Web.Optimization
- Host: GitHub
- URL: https://github.com/ogaudefroy/dynamicstylebundles
- Owner: ogaudefroy
- License: mit
- Created: 2016-11-24T19:46:03.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-06-24T13:16:17.000Z (over 8 years ago)
- Last Synced: 2025-01-23T12:15:42.975Z (9 months ago)
- Topics: asp-net, bundling, multitenant, white-label-sites
- Language: C#
- Size: 43 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# DynamicStyleBundles
A lightweight library which simplifies dynamic assets bundling via System.Web.Optimization for ASP.Net whitelabel sites.
[](https://ci.appveyor.com/project/ogaudefroy/dynamicstylebundles/branch/master)## Core Features
- Delivers dynamic style assets and bundles them (use case: white label sites)
- Feature toggled cached bundling
- Supports cache dependencies
- Multi tenancy support
## Getting up and running
### Install
Install the nuget package ; the setup will add the reference and will tweak your web.config file to add a brand new handler definition.``
### Configure your application
- Modify the handler's path to match your needs
- Implement [IAssetLoader](https://github.com/ogaudefroy/DynamicStyleBundles/blob/master/DynamicStyleBundles/IAssetLoader.cs) interface to retrieve your assets from your datastore.
- In your Application_Start method register your configuration.
```
DynamicStyleBundlesConfig.Current = new DynamicStyleBundlesConfig(() => GetAssetLoader(), "~/DynamicContent");
DynamicStyleBundlesConfig.Current.ApplyConfig();
```
### Registering your dynamic bundles
Replace your StyleBundle instantiations by DynamicStyleBundle instantiations and you're up and running to deliver dynamic assets.DynamicStyleBundle do support CDN, transforms but also multi tenancy design and feature toggle caching (see below).
## Advanced scenarios
### Feature toggled cached bundling
A common scenario when building white label sites is the capability to provide a UI where technical users can update stylesheets, images and fonts. As a consequence when applying dynamic assets bundling it can be very convenient to temporary disable the bundling only for a specific user in order to test its updates.This library implements this requirement with the [ICacheToggleProvider](https://github.com/ogaudefroy/DynamicStyleBundles/blob/master/DynamicStyleBundles/ICacheToggleProvider.cs) interface which creates an extensibility point where you can implement your own feature toggle logic.
A default toggle provider is provided if no provider is registered with the bundle: [DefaultCacheToggleProvider](https://github.com/ogaudefroy/DynamicStyleBundles/blob/master/DynamicStyleBundles/DefaultCacheToggleProvider.cs) which always activates caching.
### Multi tenancy support
By default DynamicStyleBundles supports multitenancy through its caching mechanism which generates caching keys prefixed with HTTP_HOST server variable. This behavior is implemented in [DefaultCacheKeyGenerator](https://github.com/ogaudefroy/DynamicStyleBundles/blob/master/DynamicStyleBundles/DefaultCacheKeyGenerator.cs) class.If this design doesn't match your use case you can create your own cache key generator by implementing [ICacheKeyGenerator](https://github.com/ogaudefroy/DynamicStyleBundles/blob/master/DynamicStyleBundles/ICacheKeyGenerator.cs) and registering your implementation when instantiating your DynamicStyleBundle.
### Cache dependencies
It can also be very convenient to be able to automatically refresh your bundle when an asset is edited. By default, DynamicStyleBundle provides a [TimeSpanCacheDependency](https://github.com/ogaudefroy/DynamicStyleBundles/blob/master/DynamicStyleBundles/TimeSpanCacheDependency.cs) which expires after 15 minutes.You can provide an alternate implementation by implementing the [ICacheDependencyBuilder](https://github.com/ogaudefroy/DynamicStyleBundles/blob/master/DynamicStyleBundles/ICacheDependencyBuilder.cs) interface and register it when setting the virtual path provider.