tags:

views:

87

answers:

2

Hello,

I have a Website project with a lot of aspx sites. I would like to find out is there any tool that will allow me to remove all white spaces and comments from the aspx files? I don't want to do it on run-time because it's not performance optimal. I would like to do it just before deployment.

Is there any ready tool, or should I write a simple console app, that would use REGEX to eliminate the unnecessary white spaces and comments?

Regards, Adam

+1  A: 

For what purpose? Obfuscation?

If you're just trying to reduce the size of HTTP responses to the end user, you are much better off telling the web server to use compression on your output. This zips the spaces away to nothing and gives much smaller results than ‘minification’.

(Unless you are retaining loads of <!-- comments --> in which case you should simply change them to <%-- server-side comments --%>.)

Don't try to process ASP.NET with regex. Neither HTML nor aspx-templates are regular languages and together they are much, much more complicated than regex can handle. Naïve approaches like looking for spaces outside of <[^>]*> constructs are very likely to mess up your pages.

bobince
It's because the code have a lot of comments inside, and there just to many aspx files to remove this comments by hand. I think that removing them would reduce the output by around 30%, and it's quite a lot. I think that I will try with some more complicated regexes.
Adam
You could match `<!--(.*?)-->` and replace with `<%--\1--%>` across your actual work copy of the files (not as a deployment option); you will probably break something, but at least you're likely to find out that you've broken it more quickly. Or hack up a script that will show you each match it finds before it replaces it, allowing you to Y-Y-Y-Y through them with a little review. Either way, output compression is a good thing.
bobince
A: 

Yeah, there is no need to do it on run-time. Because it can be done on compile-time. Check this link out: http://omari-o.blogspot.com/2009/09/aspnet-white-space-cleaning-with-no.html

thorn