I am presenting at Developer Conference 2012 Hyderabad

by Shravan Kumar Kasagoni on April 10, 2012

DevCon is the event which concentrates on the topics which are exclusively intended for developers and sessions included in this directly concentrates on the applicability of the technology.  Finally the agenda is out and the date is also finalized. It is to be held on 21st April 2012 at Microsoft IDC, Hyderabad. Hope it will be a grand success!

This time I am presenting on Building Single Page Apps using ASP.NET MVC 4 & ASP.NET MVC 4 Features.

DevCon2012 Logo

You can register for the event at http://devcon2012hyderabad.eventbrite.com/

You can find all the details of the event @ http://mugh.net/devcon2012/

Hope to meet you at DevCon 2012!

{ 0 comments }

Bundling and Minification support in ASP.NET MVC 4

by Shravan Kumar Kasagoni on April 5, 2012

Most of the web developers today uses multiple JavaScript and CSS files for separation the concerns, for readability & maintainability of code. This is a very good practice from a development point of view, but it often causes degradation of the overall performance of the website. Multiple JavaScript and CSS files require multiple HTTP requests from a browser, which in turn can slow down the performance & load time of your webpages.

Look at the below solution structure, it contains 5 JavaScript files & 4 CSS files:

Solution Explorer

I am including these files (5 JavaScript & 4 CSS files) into _Layout.cshtml file in my ASP.NET MVC 4 Solution.

LayoutCSHTML

Let’s start debugging this application & capture the network traffic using Internet Explorer 10 Developer toolbar (you can use IE 9 Developer toolbar also).

In IE 10 or IE 9, Press F12  or go to Tools Menu => Click on F12 developer tools to open developer toolbar. Once you open IE developer toolbar, go to Network tab, click on Start capturing button and refresh the page.

IE 10 Developer Toolbar

Let’s have look at network traffic using Firefox’s firebug add-on.

firebug

If we observer statics in both IE developer toolbar & Firebug, different JavaScript files & different CSS files are consuming different amount of time depending on the size of a particular file. All the files did not started downloading at once, because browsers can make only certain number of HTTP requests at a time depending on their behavior. Even if we look at code downloaded to client side its looks as it is (with spaces, indent etc.) what we included into page.

IE 10 Developer Toolbar

The problem is how to improve the performance of a web page?

This can be done by reducing number of HTTP requests and reducing payload (size of JavaScript & CSS files). Both can be achieved using Bundling and Minification.

  • Bundling : Process of combining all the different JavaScript and CSS files into one file (one for JavaScript and one for CSS).
  • Minification : Process of shrinking the JavaScript  and CSS content (removing all of the carriage returns,empty spaces,line feeds & shortening the variables  without changing actual functionality).

Till now it’s developer duty to do Bundling and Minification, there are multiple tools (JSMin Microsoft Ajax Minifier,Yahoo! YUI Compressor) available to do this.

The ASP.NET MVC 4 by default supports Bundling and Minification.

Bundling and Minification is implemented in very simple way in ASP.NET MVC 4, Instead of adding multiple js files & css files, now we can simply specify the below statements .

LayoutCSHTML

In code the value of  src attribute in <script> element is Scripts/js, it means under the scripts folder in solution bundle  & minify all the files with js extension, The statement bundle & minifies all the JavaScript files  under Scripts folder (It will not include files in subfolders), same is applicable for <link> element which is for css files, It will bundle & minifies all the CSS files under Styles folder (It will not include files in subfolders).

To see Bundling and Minification in action, we should add one more statement to Global.asax in Application_Start() method, that is BundleTable.Bundles.EnableDefaultBundles().

appstart

Let’s start debug the application once again & capture the network traffic.

IE 10 Developer Toolbar

Firebug

If we observer there are only 2 http requests, one for JavaScript & one for CSS. The browser will make single http request to get all JavaScript files as single JS Bundle & one more single http request to get all css files as single CSS Bundle. The time consumed to get JS Bundle & CSS Bundle also is also very less this because of Minification, Just to conform let’s have a look at the view source of webpage in browser & Response Body in detailed view of js request in toolbar.

iesource

ietoolbar2

We have only 2 statements in view source (one for js, one for css) & Response Body of js statement contains all the JavaScript files in  minified format. So the Bundling and Minification works pretty fine in ASP.NET MVC 4 with simple statements.

Now when start exploring the JavaScript Bundling And Minification, So many questions will come into mind, for example when we are using JavaScript frameworks like jQuery, we should load framework libraries first, load the user scripts next, all this will be taken care by  MVC while dealing with Bundling And Minification. It has it’s own algorithm which will first sort all the files in ascending order, then arranging them required order depending on the dependencies, this is the default behaviour.

Along with default behaviour, ASP.NET MVC 4 provides fine grain control over Bundling and Minification to create our own custom bundles, use your own algorithm to minify the files. With the help of custom bundles we can add the required files & directories to Bundles Collection in BundleTable. This very helpful because we don’t load all the files at a time, some files we load in layout page & some files in child pages on demand, So we can create  different bundles, load them on demand.

Look at the below solution the Scripts folder contains all the framework libraries, Custom folder in Scripts includes all the user written scripts, Root folder has Menu.js, Styles folder contains couple of css files.

Solution Explorer

How to create Custom JS & CSS Bundles?

Global.asax

To use this bundles in MVC views, add the virtual path of Bundle to view.

LayoutCSHTML

This works seamlessly how the default  Bundling and Minification works, end results will be same, but it gives fine grain control over behaviour of Bundling and Minification.

We have one more option for caching these bundles in client browser for one year,until  no change in source on the server. To do this MVC provided a helper.

Layout

Instead of adding plain virtual path to <link> tag or <script> tag, if we use System.Web.Optimization.BundleTable.Bundles.ResolveBundleUrl() method to add the virtual paths, It will cache the bundled & minified files in client browser for one year. How this is possible? If  we once again look at the view source of web page, it will include the hash code in the URL for both css bundle & js bundle.

source

Using the hash code the script & css will be cached in browser , when ever is their is any change in the script/css at server, it will invalidate this hash code & once again it will download  the fresh content & caches it.

Bundling and Minification support in ASP.NET MVC 4 is not just only for JS, CSS it twill seamlessly works with Coffee Script,  Less, etc..

In next article read about the internal of Bundling and Minification in ASP.NET MVC 4. ASP.NET Web Forms also supports Bundling and Minification by default from ASP.NET 4.5 version onwards, It is almost similar. One of my friend(AbhijitJana) has nice article on how Bundling And Minification works in web forms: http://bit.ly/pUqRfS.

{ 5 comments }

Join Tech Ed India 2012 Live

by Shravan Kumar Kasagoni on March 14, 2012

Catch TechEd Online!
Unable to make it to the tech event of the year? Do
not worry! We’ve got you covered with TechEd Live!
Get a real-time experience of the hottest action at
TechEd India 2012-live streaming of keynote
addresses, demos, technical tracks and more-right
where you are.
A must see for all, including developers and
administrators. Learn about new and exciting
developments in Windows Phone, Windows Azure,
Visual Studio 2011, Windows 8 and other
cutting-edge technologies.
Register now!
Watch TechEd Live unfold!
Register for TechEd Live!
Don’t Miss!
For the first time, TechEd Live unveils a cool new channel for tech enthusiasts, students and hobbyists. It covers the latest platforms and technologies that Microsoft is working on.Find more on this hip new channel!
Click here for a sneak preview of TechEd Live!

{ 0 comments }

Download Windows 8 Consumer Preview & Visual Studio 11 Beta

by Shravan Kumar Kasagoni on February 29, 2012

Hi All,

Here is long waiting Download links for Windows 8 Consumer Preview & Visual Studio 11 Beta:

windows 8

Windows 8 Consumer Preview Downloads:

  1. Windows 8 Consumer Preview 64 Bit
  2. Windows 8 Consumer Preview 32 Bit
  3. Visual Studio 11 Express Beta for Windows 8

System Requirements for Windows 8 Consumer Preview:

Windows 8 Consumer Preview works great on the same hardware that powers Windows 7:

  • Processor: 1 gigahertz (GHz) or faster
  • RAM: 1 gigabyte (GB) (32-bit) or 2 GB (64-bit)
  • Hard disk space: 16 GB (32-bit) or 20 GB (64-bit)
  • Graphics card: Microsoft DirectX 9 graphics device or higher
  • To use touch, you need a tablet or monitor that supports multi touch
  • To access Windows Store and to download and run apps, you need an active Internet connection and a screen resolution of at least 1024 x 768
  • To snap apps, you need a screen resolution of at least 1366 x 768

Visual Studio 11 Beta Downloads:

Visual Studio 11

  1. Visual Studio 11 Beta Ultimate Web Installer
  2. Visual Studio 11 Beta Ultimate ISO Download

Hardware Requirements Visual Studio 11 Beta:

  • 1.6 GHz or faster processor
  • 1 GB of RAM (1.5 GB if running on a virtual machine)
  • 10 GB of available hard disk space
  • 5400 RPM hard drive
  • DirectX 9-capable video card running at 1024 x 768 or higher display resolution

{ 0 comments }

Join us at Visual Studio 11 Developer Day, Hyderabad – 18th Feb 2012

by Shravan Kumar Kasagoni on February 14, 2012

Microsoft User Group Hyderabad (MUGH ) invites you to Developer Day on 18th Feb 2012 ( 9:30 A.M to 1.30 PM ) at Microsoft Campus , Hyderabad.  Join us to meet Meet Charles Sterling, Senior Program Manager, Visual Studio Team. Charles will deliver 90 min talks on “Application Lifecycle Management with Visual Studio 11”.  Additionally, we have two sessions on “Debug production hosted application with Intellitrace and Visual Studio 11” and “SQL Server 2012 Database Unit Testing with Visual Studio 11”.

Check out the Complete Agenda from here : http://mugh.net/vs11devday/agenda.html

Register for the event from http://mughvs11devday.eventbrite.com/

{ 0 comments }

I will be speaking at the MUGH January Developer Day on HTML 5

by Shravan Kumar Kasagoni on January 21, 2012

Microsoft User Group Hyderabad invites you to Developer Day on 29th Jan’12

Register Here: http://mughdeveloperday01.eventbrite.com

{ 0 comments }

I am a Microsoft Most Valuable Professional Now

by Shravan Kumar Kasagoni on January 1, 2012

Microsoft MVPs or Most Valuable Professionals” are recognized and awarded for their exceptional commitment to helping us improve our products and helping people around the world make the most of their Microsoft technology.”MVPs make exceptional contributions to technical communities, sharing their passion, knowledge, and know-how. Meanwhile, because MVPs hear the opinions and needs of many others in the technical community, they are well-placed to share highly focused feedback with Microsoft. MVPs are independent experts who are offered a close connection with people at Microsoft. To acknowledge MVPs’ leadership and provide a platform to help support their efforts, Microsoft often gives MVPs early access to Microsoft products, as well as the opportunity to pass on their highly targeted feedback and recommendations about product design, development, and support.

I am happy to announce that I have been awarded with the title of Microsoft MVP for ASP.NET/IIS technology area for the year Jan 2012.

Here is a glimpse of the official email that I received:

Dear Shravan Kasagoni,

Congratulations! We are pleased to present you with the 2012 Microsoft® MVP Award! This award is given to exceptional technical community leaders who actively share their high quality, real world expertise with others. We appreciate your outstanding contributions in ASP.NET/IIS technical communities during the past year.

The Microsoft MVP Award provides us the unique opportunity to celebrate and honor your significant contributions and say “Thank you for your technical leadership.”

Nestor Portillo
Director
Community & Online Support

Here is My MVP Profile: https://mvp.support.microsoft.com/profile/shravan

I would like to thank many people at this moment, encouraged me and helped during all my community & technical engagements.

First and foremost would like to thank my friends or my tech gurus, Abhijit Jana & Harish Ranganathan for their guidance and support during all my activities. I would like to thanks one more special person, He is Abhishek Kant, Former South Asia MVP Lead from Microsoft.

I would like to thanks all Microsoft User Group Hyderabad core team (Sudhakar, Geetesh, Phani, Pranav, Hima Bindu, and Muqueet) for their support.

Take this opportunity to thank one and all who have helped me to achieve this.

Wish You Happy & Prosperous New Year , Happy Coding!

{ 6 comments }

Wish you a happy and prosperous new year – 2012

by Shravan Kumar Kasagoni on January 1, 2012

{ 0 comments }