Oct 6, 2008

Very elegant way to cut few more bytes from your ASP.NET markup and optimize your bandwidth a bit (2) - Solving the puzzle

As I mentioned in my previous post, I ocassinally received errors when replacing the "javscript:__doPostBack" with "_dpb". It saved few bytes, yes, but for example the ASP Menu stopped working.

I finally found what was causing the problem. It is because of links (rendered as "a href"). The ASP Menu renders them as a href="javscript:__doPostBack()". If you remove the "javascript:" part you will have problems as the browser will not be able to understand that you are trying to call a JS function. A possible solution is to move the call to the OnClick of the "a" element, leaving "#" in the "href" attribute like this:

a href="#" onclick="_dpb()"

This will however cause a small side effect. When the user clicks on the first
of a series of links, all the links will change their css class to "visited:" css class (because the browser sees you already have visited the "#" address).

Conclusion : You can apply the above technique but it will not help you much and I think it involves to much efforts for a small effect (few bytes). If you really want to get this benefit you can replace the "javascript:__doPostBack" with "javascript:_dp" and you will get less bytes than if removing the "javascript:" part but the page will work as expected.

I am currently working on other techniques to cut more of the ASP page markup, but they are a bit more serious. I hope I will write another post soon to inform you how it is going.

No comments: