There have been a number of utilities out there for “minifying” JavaScript. Read More..
Microsoft Ajax Minifier by default will try to reduce the code as much as possible: removal of comments, whitespace, and unnecessary semicolons and curly-braces; renaming of local variables and functions to shorter names; and removal of unused or unnecessary code. The -rename and –unused switches can be used to alter this default behavior.
Minifications:
Microsoft Ajax Minifier minifies script by parsing the source code into a JavaScript Syntax Parse Tree using code based on the ROTOR sources published by Microsoft. Once the original sources have been parsed, the tree is manipulated, and then walked to output the minimum amount of JavaScript code required to reproduce a comparable parse tree. Microsoft Ajax Minifier does not alter the source file.
Default minification are as:
Remove unnecessary white space.
Remove comments (except for statement-level “important” comments).
Remove unnecessary semicolons.
Remove curly-braces around most single-statement blocks.
Rename local variables and function.
Determine best string delimiters (single- or double-quotes) based on which option will generate the fewer escaped characters within the string.
Combine multiple adjacent variable declarations.
Remove empty parameter lists on constructors.
Remove unreferenced names for named function expressions.
Remove unreferenced local functions.
Remove many instances of unreachable code.
Few examples:
Origianl
Minified
if ( a == 0 )
{
a = 10;
alert(b/a);
}
if(a==0){a=10;alert(b/a)}
var a = 0;
var b = "some string";
var c = 3.14;
var a=0,b="some string",c=3.14;
if ( a == 0 )
{
for(var o in opts)
{
if ( o > 0 )
{
a += o;
}
}
}
else
{
b = c / a;
}
if(a==0){for(var o in opts)if(o>0)a+=o}else b=c/a
function DivideTwoNumbers(numerator, denominator, unsedparameter )
{
return numerator / denominator;
}
function a(a,b){return a/b}
Usage:
Two approaches:
·Command Line
·As a Build Task
Command Line: After you install the Microsoft Ajax Minifier, you can use the tool from the command line. Open the Microsoft Ajax Minifier Command Prompt from the Microsoft Ajax Minifier program group. Next, enter the name of an input file and the name of an output file like this:
ajaxmin test.js -o test.min.js
ajaxmin test.css -o test.min.css
Build Task:
·You can integrate the Microsoft Ajax Minifier into your Visual Studio Build process.
·Every time you perform a build in a Visual Studio ASP.NET project, you can minify all of your JavaScript and Cascading Style Sheet files automatically.
·You can use the Ajax Minifier with both ASP.NET Web Forms and ASP.NET MVC Web Application Projects (WAPs).
Note: However, you cannot use the minifier with ASP.NET Web Forms Websites.
JavaScript has the dubious quality of not being compiled. The source code text for the program is downloaded by the client, parsed, and the interpreted by the browser. Verbose, easy-to-maintain coding styles actually hurts performance with JavaScript, as it Greatly Increases The Page Weight transmitted to the client.
There have been a number of utilities out there for “minifying” JavaScript.
·The first level of minification is to Remove Whitespace And Comments. This is a minimum amount to be expected for a website – comments and whitespace can be extracted from the sources without changing the semantics of the code. The third-party tool Jsmin from Douglas Crockford (http://www.crockford.com/javascript/jsmin.html) is an excellent example of this kind of minification.
·The second level of minification is to also Remove Excessive Semicolons And Curly-Braces. In JavaScript, semicolons are not statement terminators as in C or C#, they are separators. Therefore the final statement in a block does not require a semicolon after it. Curly braces, although highly-recommended for properly-maintained JavaScript code, also don’t need to be around single-statement blocks. We don’t have to send those bytes to the user, however, and they can and should be removed before deployment. Developers also tend to over-parenthesize their expressions in order to make them more readable or to ensure that the intended precedence will unfold as expected. Extra parentheses can also be removed from the output. The danger is that this level of minification could alter the semantics of the code if not done properly.
·The next level of minification is to recognize the fact that Local Variables And Functions are referenced only within a known scope, and can therefore have their identifiers Shrunk Down To Shorter Names. This is highly useful because developers can code with longer, semantic names in their local functions and variables in order to increase readability and maintainability without having to penalize the client with large downloads. These modifications must be very carefully made because this level of change to the sources is greatly increased. Scope chains must be respected or the code will cease to work properly, and global variables cannot be touched (since they may be referenced from other script files).
·The next level is to analyze the code and recognize & EliminateUnreachable Statements And Functions, And Unused Variables. Eliminating these bytes from the download can go a long way to shrinking your page weight, without having to require constant manual reviews of the code base. Again, this must be very carefully done to ensure that a function or variable really isn’t referenced.
·The next level of minification is to Analyze The Usage Of Global Variables And Object Properties, and to Provide Shortcuts in the code the replace the longer, repeatedly used constructs. For example, if the algorithm detects that a script repeated accesses the “window” global object, a one-letter variable can be set to the window object, and every other instance of “window” in the code can be replaced with that single letter. This not only modifies the existing sources, but also injects new code into the JavaScript. What can be replaced must also be carefully determined to make sure that the values and objects cached in the short local variables will remain the same value for the life of the variable.
The final release of VS 2010 and Visual Web Developer 2010 will have ASP.NET MVC 2 built-in – so you won't need an additional install in order to use ASP.NET MVC 2 with them.
ASP.NET MVC 2 is the next significant update of ASP.NET MVC.
·It is a compatible update to ASP.NET MVC 1 – so all the knowledge, skills, code, and extensions you already have with ASP.NET MVC continue to work and apply going forward.
·ASP.NET MVC 2 can be installed side-by-side with ASP.NET MVC 1
One of the new features in Silverlight 3 is providing an application navigation framework via the Frame and Page controls in the APIs. If you saw my guide to Silverlight 3, you may have seen the section on navigation which describes the functionality and as well has a link to a video tutorial about it.
I wanted to augment that tutorial with some additional information about URI routing, which I think is one of the great features of the framework. You see typically your UriMapper might have a 1:1 mapping and look something like this (note in my sample here I'm putting this in App.xaml, but the model may change in the future of where you can/should place UriMapper):
But what if you still wanted to provide friendlier routes, obfuscate the physical location of the view, but handle the default scenario? You can as long as you follow your own naming conventions. Take for instance if we contain all our pages in a folder called Views in our application. We could then map our routes like this:
You could also follow some naming conventions if you wanted to make sure you limited it to only pages or something so you require the view page to be named SomethingPage.xaml and then can have a route like:
A request to About-Us, History or About would navigate to /Views/AboutPage.xaml regardless. This provides you some flexibility and granularity in your implementation and also provides additional SEO points for your content.
I really like the UriMapper in the navigation framework and have been lobbying to change the default templates Visual Studio spits out to use the UriMapper by default. It provides you with a cleaner (and perhaps shorter) URI as well as obfuscates your "code" from your URI logic. Be sure to check out the video if you aren't familiar with the framework at all.
In fact in Silverlight 3,a new project template is supported , which by default has provison for SL3 Navigation.