Developer forum

Forum » Development » RE: Minify HTML

RE: Minify HTML

Marco Santos
Reply

Hello.

I'm trying to find a way to minify our HTML for a project, and I am not sure what is the best way to go about it. From what I can find the best option seems to be through the OnOutput notification, where I can minify the template HTML field. However, this could also have cshtml, and removing the whitespace breaks the template output generation. Is there a hook that you know of that I can use to get the generated output for the page and minify that before sending out to the client?

Thanks.

Marco Santos


Replies

 
Morten Bengtson
Reply
This post has been marked as an answer

Another option is to register an IHttpModule which minifies the HTML before it is sent to the client.

I have previously used WebMarkupMin (includes various configurable modules and handlers) and it worked great. However, it caused some issues in the Admin area, so I had to prevent the module from processing HTML when the URL contained "/Admin/". It also does HTTP compression (gzip / deflate), but you need to make sure it doesn't conflict with the compression done by DW.

BR Morten

Votes for this answer: 1
 
Nicolai Høeg Pedersen
Reply

OnOutput is a possibility - but Mortens suggestion I think is better.

If you are using gzip in your solution already (default DW behavior), the performance improvement is probably not going to be very big. Also note that minifying in itself is not 'free' - it also takes time to run on every page view. So make sure you test that you actually gain something from this excersise.

BR Nicolai

 
Marco Santos
Reply

Thanks for the help guys.

 

You must be logged in to post in the forum