NuGet packageOwin.Framework.Versioning
GitHub sourceOwinFramework.Versioning

Home |  Readme

The OwinFramework.Versioning Project

This middleware will improve the performance of your web site by adding a version number to the URLs of static assets and instructing the browser to cache them indefinately.

Each time you release a new version of your web site you should increment the version number so that the browser sees them as new assets and fetches them from the server. Once the server has a particular version of an asset it will keep hold of it any not request it again, this improves the user experience and reduces load on your servers.

This middleware performs these actions:

  • It will intercept HTML, CSS and JS output on its way out to the browser, replacing a special marker with the current version number. This marker must be placed immediately before the file extension. For example <img src="button_v5.png" /> will be replaced with <img src="button_v3.png" /> if the current version number is 3. This HTML, CSS and JS can be produced by any downstream middleware including Static Files and Pages.
  • It will intercept incomming requests for assets (based on file extension) and strip off the version number before forwarding the request to the downstream middleware. This makes the versioning operation transparent to the middleware downstream.

Adding this middleware to the Owin pipeline

    .ConfigureWith(config, "/owinFramework/middleware/staticFiles");    
The assumes that you are using Ninject as your IoC container, and followed the getting started walkthrough. If this is not the case then you will need to adjust the code to work in your application.

Default Configuration

The configuration below is the configuration you will get by default if you do not provide a configuration for this middleware.

   "owinFramework": {
      "middleware": {
         "session": {
            "documentationRootUrl": "/versioning",
            "version": 1,
            "mimeTypes": [ "text/html", "text/css", "application/javascript" ],
            "fileExtensions": [],
            "browserCacheTime": "365d",
            "exactVersion": false,
            "analyticsEnabled": true

Configuration Notes

  • If you set the exactVersion to true then requests for assets with the wrong version number will result in a 404 (not found) response to the browser. The default is to return the current content nomatter which version is requested.
  • You need to configure fileExtensions to the set of file extensions that you want this middleware to handle or it will not work.