asp.net publish with whitespace removed - asp.net

Obviously having whitespace in css, aspx and html pages is a great advantage at design time. But is there a way to (a tool that will) clear all the whitespace from all the files and possibly merge javascript and css files in a more optimal way.
I am using asp.net themes so there are quite a lot of separate css files that would be improved through some form of automated combining. I have seen a few http modules but that isn't quite what I want I just want to run something over the published project beofre sending it to the server.
EDIT: Compression at least in IIS is unfortunately not an option, we are currently running it on the same IIS server as a third party web based student management system. It doesn't like compression and the IIS options don't seem to be per application pool. I did apply asp.net compression but the bulk of my extra data seems to be the app_themes which I know would compress well I just don't want to have to manually go through compressing all the css separately.

An empirical study on the effect of removing white space from a not-untypical website (Drupal) showed minimal effects. (site also contains some links to non .net html white space removal tools)
I have gotten magical improvements in page size by aggressively managing viewstate size and using Blowery's http compression module.
Another strategy is to do minifiation (merging many css files into one). Telerik has such a component RadStyleSheetManager, it works only with style sheets embedded into assemblies.

There is another way
http://omari-o.blogspot.com/2009/09/aspnet-white-space-cleaning-with-no.html

I think one of the reasons that this was never included in .NET was because they expected you to turn on server compression in these scenarios. IMO I don't agree with this -- I think it's a shame that at least aspnet_compiler.exe can't do this optimization. It would be such a great performance boost on uncompressed connections. Anyway, you can enable compression on IIS 6:
http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/d52ff289-94d3-4085-bc4e-24eb4f312e0e.mspx?mfr=true
And it's even easier and more flexible in IIS7 to do so. I hope someone has a better solution than I!

4 guys from Rolla just published an article on a http module that removes white space. You would need IIS 7 in integrated mode to make it work for css (or possibly IIS6 with wildcard mappings)
It looks more like a proof of concept, but the code is free.

i found this:
http://msdn.microsoft.com/en-us/library/aa719805(VS.71).aspx
greets!

Related

Is there an equivalent to the mod_pagespeed Apache module for IIS?

Is there an equivalent to mod_pagespeed Apache module but for IIS?
IISpeed is a full-featured pagespeed port to IIS. It requires a paid license for production servers to avoid showing a banner, but it is free to try out.
Full disclosure: I am one of the people working on the port. So I will not push this further than mentioning the port.
This isn't a direct mod_pagespeed replacement but does some work towards reducing the number of requests, minifying and bundling JS and CSS.
It even automatically provides lossless compression of PNG-images and creates sprites of your background images. See the RequestReduce library.
(not tried it myself)
There aren't any solutions that do exactly what mod_pagespeed does at this time. There are several individual packages you could use to match most of the functionality.
The product #alirobe mentioned (aptimize) does many of them.
YUI Compressor (.Net port) works on JavaScript and CSS minification
IIS (version 5.1 and newer; though much easier to configure in IIS7+) can be configured to do GZIP compression for static and dynamic files
You can set Expires headers in IIS for static files, and in back-end .Net code for dynamic pages
.Net 2.0 can do some script combining with explicit configuration via the <asp:ScriptManager> control
.Net 4.0 has even more script combining abilities and can do more with less configuration. (example discussion of some of the new features)
UPDATE: .Net 4.5 further extends script combining with minification.
Scott Hanselman wrote The Importance (and Ease) of Minifying your CSS and JavaScript and Optimizing PNGs for your Blog or Website that lists many other individual packages that can be combined.
No.
Not right now, at least.
Do keep in mind, however, that mod_pagespeed is an automation of the best practices of web caching and speeding and you can manually set those up. PageSpeed Extension and YSlow extension are both very helpful to understand what should be optimized.
I don't believe there's a free one, but there is : http://www.aptimize.com/
update: Of course, if you're using any other automated deployment tool, you could do quite a bit by integrating commandline tools into the build batch script. HTML5 Boilerplate is probably your best practice reference there. You can also use server-side tricks like HttpCombine.ashx.

Improving the web site performance

I have a pretty big web site (asp.net web) and I have used JavaScript intensively (jquery,custom javascipt, etc) and also The theme and CSS. Right now I have a huge amount of js and css files in my system and I am thinking about minifying and smashing the js and css to improve the performance. So, please advice me the suitable tools and technologies to be used and please suggest me the best practices to be applied in these scenario.
There are a couple of things you could try to improve performance.
Enable GZIP
Enable 'Retail' attribute in machine.config
Enable Page Caching
I've listed the techniques we have used at our organisation to improve the performance of our web applications. With the exception of GZIP the other two probably won't have a direct effect on the JS and CSS files but will save you valuable loading time in other areas making your web site much faster.
We always see huge increases in speed and performance when the retail attribute is set to 'True' - all forms of debugging are disabled in this mode which makes the site more responsive.
Obviously you only want this setting on your live server.
If you're using jQuery, you should already be using the minified version on your production site.
For your own Javascript, there's Douglas Crockford's original minifier, or you could use the Microsoft Ajax Minifier, which you can add as an MSBuild task - there's an overview here.
There's a number of CSS minifiers referenced in the answers to this SO question.
Best practices are great but, at least in the case of performance, the question is more about the right practice. The only way to know is to:
Measure
Try
Measure Again
Compare/Contrast
It is almost always a trade-off with optimizing software. You have to consider how a change effects readability, scalability, security, deployment complexity, and probably a lot of other ity's I am not thinking of.
Having said all that the practices you are looking for are pretty much here.
To make my point though consider the rule Use a CDN. This seems like an obvious choice for something universal like jquery. You can use both MSFT and Google for this. You have the potential advantage of parallel download (depending up on the client browser) and the added possibility of already being in the client cache (from other site they may have visited). Plus they are likely serving it closer to the user than you are.
But the trade off to consider is that it is going to eat some bandwidth so if you are building something that is sitting in the Intranet, don't do this. You also introduce the possibility of failure from an external source. You can work around that by adding more code.
Perhaps most importantly though is that using a CDN is in direct contrast to the first rule, reduce HTTP requests. If you can combine and minimize all your js and load it more efficiently locally then you should do so. How do you know?
You have to:
Measure
Try
Measure Again
Compare/Contrast
Have fun!

Yui files are too heavy and affect site's performance

I ve developed an asp.net web application with YUI as the javascript library... My site was very slow that it took three minutes to view my page on my first visit....
When inspected through firebug, My yui file was too heavy with size
278kb...
what can be done to improve performance?
278k is less than many images that appear on websites, and YUI is only as heavy as the component stack that you have requested. The common core package yahoo-dom-event.js is 37k (12k gzipped), so you are requesting at least a few other modules. That said, even across a slow connection, 278k should not cause a 3 minute delay. I suspect there is something else causing the performance issue.
There are many tactics for improving page performance. As MontyBongo suggests, use the Yahoo! CDN. If you are hosting the files yourself, make sure you have gzip enabled on your server. One benefit to using the CDN is the ability to use the Combo handler, which bundles all modules into a single script file. If self hosted, you should look into creating manual rollups of the files you are using to emulate this. Also, look into the YUI Loader to bring in module files asynchronously. http://developer.yahoo.com/yui/yuiloader/
Otherwise, look at http://developer.yahoo.com/performance/ and ask on yuilibrary.com/forum for advice. Please note that you should always supply some code for reference when asking for advice to improve it. Paste code snippets inline, link to larger snippets on http://pastie.org or http://gist.github.com, link to the page in question, or (best of all) link to a reduced page that illustrates in isolation the issue you want to address.
Try compressing the javascript with gzip, if possible use the Yahoo or Google CDN to deliver the files:
http://developer.yahoo.com/yui/articles/hosting/
Also try install YSlow, it can give you some good feedback on whats causing your page to load slowly, and provides some tips on optimizing the javascript delivery
http://developer.yahoo.com/yslow/
I agree that YUI is a bit too heavy for many sites.
In case it helps, you might want to have a look at my book for some ideas on how to make things run faster: Ultra-Fast ASP.NET: Build Ultra-Fast and Ultra-Scalable web sites using ASP.NET and SQL Server.

Good tool to minimize HTML footprint?

Does anyone know a good tool that can be run on a page (for asp.net, for example) to help to minimize the footprint size of the page?
The page will have typical items: HTML, Javascript, etc.
I've heard of Javascript crunchers in the past, that will make the size of the code as compact as possible (and obfuscate it, I suppose).
The goal is to help optimize the page size (make it as small as possible for speed, without changing anything).
Is this possible?
You could configure your web server to compress the page on the fly (and possibly cache the compressed version) for any client that indicates it can take a gzip or zip (or other) encoding, which is pretty much all of them.
Well, its not a automatic cleaner-upper, but I like YSlow for optimizing pages. And the YUI Compressor can minify your javascript.
If you're really interested in javascript, the keyword is "minify".
Also, look at this question just posted: HTML and stuff
Hope that helps!
Yep, definitely. I am not an asp.net guy, but things you could look for (as others have said):
gzip compression for the page - a
server option
js: like you said, there are
minifying options for javascript,
which in turn can be gzipped as
well.
css: there are minifying options
just like javascript, and can also
be gzipped.
Our java apps use pack:tag. Maybe you could find a similar .net replacement.
Yslow, already mentioned, can show what improvements you can make.
Search for some ASP .NET Compression techniques, if you're on IIS6 I recommend you MbCompression, however if you're running IIS 7 it has great built-in HTTP compression support, you can define which files get compressed based on their MIME type in your configuration files.
I personally would not sacrifice readability and maintainability for size.
Dynamic web server compression saved me a TON (given text compresses so well), and further optimization would have gained me very little.
A bit of fundamentals:
IIS saves compressed response of JS/CSS/Html files on disk so, subsequent requests for JS/CSS is served from Disk(bypassing step of compression). While compressed response for ASPX/ASCX are not cached on disk, since response varies from request to request.
Therefore, Best practise is to keep Javascript/CSS in their own files and avoid putting inline CSS/Script in aspx/ascx.
Broadly there are two ways to reduce Page-Size/HTML
1) Compression by webserver/HTTPModule
[Enable IIS 6 HTTP Compression][1]
2) Obfuscation/compression by third party tool - JASOB is my favourite one.
It can also compress/obfuscate javascript/css code from your php/asp.net/perl/jsp/XSLT file. And If like vanila DOS then there's command line interface too.
I have used it in several ASP.NET projects, I just select my webproject directory and JASOB provides nice option to publish obfuscated version of webproject directory. This means it obfuscates javascript/css from all files lying under your webproject directory and yeah it traverses sub directories too. And All of this in one click.
Hope it helps,
Maulik Modi
http://www.jasob.com/Features.html
[1]: - http://msmvps.com/blogs/omar/archive/2006/08/10/iis-6-compression-quickest-and-effective-way-to-do-it-for-asp-net-compression.aspx

Speeding up an ASP.Net Web Site or Application

I have an Ajax.Net enabled ASP.Net 2.0 web site. Hosting for both the site and the database are out of my control as is the database's schema. In testing on hardware I do control the site performs well however on the client's hardware, there are noticeable delays when reloading or changing pages.
What I would like to do is make my application as compact and speedy as possible when I deliver it. One idea is to set expiration dates for all of the site's static resources so they aren't recalled on page loads. By resources I mean images, linked style sheets and JavaScript source files. Is there an easy way to do this?
What other ways are there to optimize a .Net web site?
UPDATE:
I've run YSlow on the site and the areas where I am getting hit the hardest are in the number of JavaScript and Style Sheets being loaded (23 JS files and 5 style sheets). All but one (the main style sheet) has been inserted by Ajax.net and Asp. Why so many?
Script Combining in .net 3.5 SP1
Best Practices for fast websites
HTTP Compression (gzip)
Compress JS / CSS (different than http compression, minify javascript)
YUI Compressor
.NET YUI Compressor
My best advice is to check out the YUI content. They have some great articles that talk about things like CSS sprites and have some nice javascript libraries to help reduce the number of requests the browser is making.
If you are using Firefox to test your website, you might want to try a nifty Firefox extension from Yahoo! called YSlow.
It analyzes your web pages and provides grades from A-F (A being the Best and F being the worst) for each of the best practices, for high performance websites. It will help you to track down the elements of your website which you could optimize to gain speedups.
UPDATE
Now YSlow extension is compatible with all modern browsers such as Firefox, Chrome, Opera, Safari and others, read more here.
Turn viewstate off by default, it will be a night and day difference on even the most simple pages.
I wrote a blog post about improving ASP.NET page performance this a couple months back. Here are some quick & easy ways -
Turn off view state
Turn off event validation
Implement HTTP gzip/deflate compression to reduce the response size (number of bytes the server has to send back to the client)
Try to optimize/minimize your database calls for each request
I think you really need to be able to get some actual PerfMon data/telemetry from the app whilst running in production to be able to make an enlightened decision about what to optimise.
As a throw away tip I'd make sure your app is deployed as a Release build and set debug="false" in the 'compilation' section of your web.config.
You seem to be starting by assuming that your problem is download size - that may not necessarily be the case. You should do some experimentation with your ASP.NET site to determine if there are areas in your code which are causing undue delays. If it turns out that download size is not your problem, you'll need to find ways to cache your results (look into output caching, which is an ASP.NET feature) or optimize your code.
In any case - the first step when looking at a performance issue is always to verify your assumptions first, then decide on a course of action.
Have you tried these tips?
http://weblogs.asp.net/haroonwaheed/archive/2008/06/30/ASP.NET-Performance-Tips.aspx
You could start looking at caching strategies. Static files like CSS (even compressed ones) and images (even optimized ones) should only need to be downloaded once by the browser for a period of time.
Scirpt combining for AJAX has already been mentioned, but I didn't notice reference to the ScriptReferenceProfiler MS has released on codeplex to help figure out what to combine. Mike Ormond has a good start point on this.
Another tip if you're doing a lot of INSERTs to your database is to double check your server's disk caching is switched on. Case in point, I had an data importer doing 1.2 million inserts during a run. Took 4 hours and change without caching on. Took 16 minutes with it on.
A general thing when using ASP.NET and Ajax (any Ajax library) together is to avoid elephanting your Page_Load and Page_Init (and their method counterparts) things since these will be executing on every Ajax Request.
When that is said I would seriously ditch ASP.NET AJAX and use anything else...
Anthem.NET, AjaxPRO.NET, jQuery or whatever else than ASP.NET AJAX...
Of course I would use Ra-Ajax myself since that's my project. But then again I am biased...
You could turn on compression based on your client supporting it. See this article: link text
Static resources shouldn't be resent unless changed. IIS will send a response code which tells the browser to use the cached version.
You could also look at ASP.NET output caching, which can be applied fairly granularly to different portions of your page:
http://msdn.microsoft.com/en-us/library/xsbfdd8c(VS.71).aspx

Resources