如何从服务器响应中删除空格和换行符?
当我使用浏览器/AJAX 请求请求页面时,我看到很多空格和换行符,我认为这一定会增加一些检索响应的开销,因为它们也属于字符意味着字节和大小。正确的 ?
有什么方法可以在从服务器发送时将其删除吗?如何 ? (我使用IIS和asp.net进行开发)
When i request a page using browser / AJAX request i see lot of spaces and newlines which i think must be adding some overhead for retrieving the response as they too belong to characters means bytes and size. right ?
Is there some way it can be removed while sending from the server ? how ?
(I am using IIS and asp.net for development)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
有一些 http 模块可以满足您的要求,
例如这里是一个
http://madskristensen.net/post/ A-whitespace-removal-HTTP-module-for-ASPNET-20.aspx
但在我看来,在某些情况中,您不需要这样做,因为您花费了更多时间在服务器上清除页面,而不是发送它,特别是如果它是 gZipped 的。一个好的解决方案是手动缓存最终的透明页面,然后发送缓存的内容(在需要时更新它等),但这是更多的代码。
还有类似问题
asp.net MVC ActionFilter 用于删除结果中的空行< /a>
asp.net MVC ActionFilter 用于删除空行结果
缩小 ASP.NET 应用程序的 Html 输出
谷歌搜索的关键是“Minify Html”
There are some http modules that make all ready what you ask
For example here is one
http://madskristensen.net/post/A-whitespace-removal-HTTP-module-for-ASPNET-20.aspx
How ever in some cases in my opinion is that you do not need to do that because you spend more time on server clearing the page, than send it, especial if it is gZipped. One good solution is to manual cache the final clear page, and then send the cached (update it when its needed etc), but this is a lot more code.
Also similar questions
asp.net MVC ActionFilter for remove empty lines in result
asp.net MVC ActionFilter for remove empty lines in result
Minify Html output of ASP.NET Application
And the keys to search on google is "Minify Html"