Return CacheControllerExtensions.RenderCacheResult(key, version, type) Public CacheResult CacheContent( string key, string version, string type) Return new CacheResult(keyname, version, type) ( string keyname, string version, string type) Public static CacheResult RenderCacheResult Public static class CacheControllerExtensions M圜ombiner.ProcessRequest(context.HttpContext) ( this._keyname, this._version, this._type) ScriptCombiner m圜ombiner = new ScriptCombiner Throw new ArgumentNullException( " context") Public override void ExecuteResult(ControllerContext context) If ( type.ToLower().Contains( " javascript") ) Public CacheResult( string keyname, string version, string type) Next, let’s take a look at our cache controller. = A name value to inform whether we are handling a CSS or JavaScript request. If we use JavaScriptInclude in our URL, we will combine all the JavaScript files in the value list. Here we see we have a key name for CSS and a key name for JavaScript. First in my master page, I place the following markup. To this end, let’s get right into the code and show how this works. When using a path to an HTTPHandler in my markup that was not registered with my IContollerFactory factory, DI, MVC and the HTTP handler were not playing nicely. In addition, I was using Structure Map dependency injection. I wanted to stay consistent with MVC pattern by leveraging my routes. I use a lot of the same techniques but the main difference is that I use a custom Controller and ActionResult rather than a HttpHandler to handle the minify/combine/render. The impetus for this article was based on the article by Khaled Atashbahar. In short, we can ensure our clients have the necessary upgraded JavaScript files in order execute new functionality and not the files stored in the browser's cache. This becomes increasingly important when using AJAX techniques within an application that introduce new features and functionality. Similarly, it will show how we can force a client side refresh of the same CSS and JavaScript files (meaning we don't have to change our file names). The goal was to improve overall performance on the client side. More specifically it will show how to deliver compressed, minified, combined and cached CSS / JavaScript files in the context of an ASP.NET MVC application. This article will present a technique for delivering CSS and JavaScript files to a client within an ASP.NET MVC application.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |