asp.netoptimizationorganization

Optimizing and organizing ASP.NET content


I have a new ASP.NET Web Forms project that was started about 6 months ago. Being as how the project is still fairly new and in its infancy, this hasn't been much of a problem till recently.

The application is an ASP.NET Web Form application with a C# and SQL Server back end and an HTML5 and jQuery front end. The application is mostly ajax powered with very little post backs. It consists of mostly jQuery ajax calls to C# WebMethods.

The problem I am running into is some of my aspx pages are over 50kb in size with all the javascript and jQuery that is in the aspx page. I would like to move a lot of this javascript and jQuery code into separate files, but most of it consists of code that use the aspx <%= %> tags, which makes moving it a difficult (if not impossible) task.

It is getting tedious to find things in the code. I am wondering if there is a way to optimize the code (by somehow reducing the size of the aspx file) and if there is a good way to keep all this jQuery and javascript organized better so that finding things are a little bit easier? Also, is there maybe a javascript minifier that will minify the javascript inside an aspx page?

Any help would be appreciated!


Solution

  • Since you are using AJAX, I'm assuming you're using HTML markup, not any of the web controls. If so, one thing you can do is trun of ViewState in the aspx page. I was in the same position a few years ago, and decided to switch the Asp.net MVC. I would recommend you look into that. It gives you a much better development model, with minimal overhead.

    Also, is you JS/CSS minified? I'm still confused about why "...but most of it consists of code that use the aspx <%= %> tags, which makes moving it a difficult (if not impossible) task."

    WebForms, like MVC, also now supports bundling and minifications of JS files, check this out: http://blogs.msdn.com/b/rickandy/archive/2012/08/14/adding-bundling-and-minification-to-web-forms.aspx

    Update: As OP pointed out, for .Net 3.5, you can use http://getcassette.net/ for bundling and minification.