Code Monkey home page Code Monkey logo

dynamicstylebundles's Introduction

DynamicStyleBundles

A lightweight library which simplifies dynamic assets bundling via System.Web.Optimization for ASP.Net whitelabel sites. Build status

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.

<add name="DynamicStyleBundles" path="DynamicContent/*" verb="GET" type="DynamicStyleBundles.HttpHandlerFactory, DynamicStyleBundles" preCondition="integratedMode" />

Configure your application

  • Modify the handler's path to match your needs
  • Implement IAssetLoader 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 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 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 class.

If this design doesn't match your use case you can create your own cache key generator by implementing ICacheKeyGenerator 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 which expires after 15 minutes.

You can provide an alternate implementation by implementing the ICacheDependencyBuilder interface and register it when setting the virtual path provider.

dynamicstylebundles's People

Contributors

ogaudefroy avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.