Search code examples
asp.nethtmlwhitespacegeneratedlistbox-control

ASP.NET ListBox - Condense generated html


I have an ASP.NET page that has multiple (11) ListBox controls on. Some of these ListBoxes can have many options (100 or more).

The issue I have is that the response size of the page is 106kb which is down to the html generated from all of the ListBox options.

At present it is being padded out in the source like:

<option value="1">
    Test1
</option><option value="2">
    Test2
</option><option value="3">
    Test3
</option>

Would it not be smaller in size if condensed? Such as:

<option value="1">Test1</option><option value="2">Test2</option><option value="3">Test3</option>

Firstly, is whitespace actually a contributing factor here?

Secondly, if whitespace is an issue, what would be the best way to change the way html is generated for ListBox controls?

I appreciate there may be more "global" compression solutions; however for now I'm specifically looking at ListBox controls and their markup.


Solution

  • In all cases you will need the options of the select element to exist so there is no way to remove this as per your comments so i will suggest that at page load you render the listboxes with empty options then with the javascript on the page load event, you make an ajax request to get the list of options available for each checkbox and draw them in the html with javascript, this way, the request will be cached so that everytime you will call the ajax request that return the list options, it will be cached so it will be very fast.

    Let me know if you want help in this approach.