1

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.

Brett Postin
  • 11,215
  • 10
  • 60
  • 95

3 Answers3

1

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.

Maciej
  • 7,871
  • 1
  • 31
  • 36
0

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.

Paddy
  • 33,309
  • 15
  • 79
  • 114
  • I understand your point, however these listboxes act as filters within a web application and I'm restricted by the existing look and feel of the app. Some of the listboxes are themselves filtered based on others, which makes them more useable. However the initial load state is essentially "list all" which leads to such a significant number of options. – Brett Postin Feb 22 '12 at 10:39
  • Maybe consider having a different initial load state - list all is rarely useful for a large number of records. – Paddy Feb 22 '12 at 10:47
  • In the context of this page which contains a grid of records, the list all state makes sense. It is properly paged so the number of records isn't an issue. However the number of filters and the generated markup is the issue for my response size. I appreciate your comments however. – Brett Postin Feb 22 '12 at 10:58
  • As another suggestion - if list all is your default, why not start with no listboxes populated apart from the ones that 'cascade' your listbox populations - you could then populate the filtered ones only on first selection of a 'parent'. – Paddy Feb 22 '12 at 11:00
0

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.

Samir Adel
  • 2,691
  • 2
  • 15
  • 16