ASP.NET ListBox - 压缩生成的 html
我有一个 ASP.NET 页面,其中有多个 (11) ListBox 控件。其中一些列表框可以有许多选项(100 个或更多)。
我遇到的问题是页面的响应大小为 106kb,这取决于所有 ListBox 选项生成的 html。
目前它正在源中被填充,例如:
<option value="1">
Test1
</option><option value="2">
Test2
</option><option value="3">
Test3
</option>
如果压缩,它的尺寸不会更小吗?例如:
<option value="1">Test1</option><option value="2">Test2</option><option value="3">Test3</option>
首先,空格实际上是这里的一个促成因素吗?
其次,如果空格是一个问题,那么更改 ListBox 控件生成 html 的方式的最佳方法是什么?
我很欣赏可能有更多的“全局”压缩解决方案;不过现在我专门研究 ListBox 控件及其标记。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
去掉空格(新行)几乎不会带来任何好处。
您可以花一些时间创建自己的列表框控件,该控件将使用简约标签使其看起来像这样:
当然您可以 启用 IIS 压缩。
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:
And of course you can enable IIS compression.
在所有情况下,您都需要存在 select 元素的选项,因此无法根据您的评论删除它,因此我建议在页面加载时使用空选项渲染列表框,然后在页面加载事件上使用 javascript ,您发出一个ajax请求来获取每个复选框可用的选项列表,并使用javascript将它们绘制在html中,这样,该请求将被缓存,以便每次您调用返回列表选项的ajax请求时,它都会被缓存所以它会非常快。
如果您需要此方法的帮助,请告诉我。
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.
我建议包含 100 个项目的列表框无论如何都不是特别有用,并且建议您查看显示这些选择的不同方式(例如您在本网站上看到的标签选择自动完成功能可能是合适的)。
删除这里的空白对你来说没什么好处。
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.