Question

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.

Was it helpful?

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.

OTHER TIPS

You would gain almost nothing by getting rid of white spaces (new lines).

You can invest some time in creating your own list box control that would use minimalistic tags to make it look for example like that:

<c1:MyListBox>
    <o v="1">
        Test1
    </o>
    <o v="2">
        Test2
    </o>
    <o v="3">
        Test3
    </o>
</c1:MyListBox>

And of course you can enable IIS compression.

I would suggest that a listbox with 100 items in it is not particularly usable anyway and would suggest that you look at a different way of displaying these selects (something like the tag selection autocomplete that you see on this site may be appropriate).

Removing the whitespace here will gain you little.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top