ruby on Rails 3 去除 html 空白
是:
<table >
<tbody >
<tr >
<td valign="..." style="..." >
...
客户端应该获得:(视图输出中不需要任何空格!)
<table><tbody><tr><td valign="..." style="">...
rails 3 的方法是什么没有自行车?
was:
<table >
<tbody >
<tr >
<td valign="..." style="..." >
...
client should obtain: (you dont need any whitespace in view's output!)
<table><tbody><tr><td valign="..." style="">...
what is rails 3 way to do this without bicycles?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这确实是一个美观问题,并且对浏览器渲染没有任何影响。如果您担心“最小化页面大小”,这不会给您带来任何明显的变化(并且会花费您的服务器功率来清理每个请求的输出)。启用服务器 gzip 压缩将是一个更好的选择。
但是,如果您确定要执行此操作,请查看 Tidy
This is really an aesthetic issue, and doesn't have any effect on browser rendering. If you're worried about "minimizing the page size", this would not give you any noticeable changes (and would cost you server power to cleanup the output on every single request). Enabling server gzip compression would be a far better option.
However, if you are sure you want to do this, then checkout Tidy
如果您使用 HAML,则可以指定选项
:ugly
来指示它不要缩进生成的 html。更多信息请参见文档。
我不知道 erb 的任何设置,但根据我的理解,erb 不会格式化您的代码,您会格式化 if 。如果您不想缩进 html,则应该这样编写(或在部署之前预处理您的 erb 模板)
If you're using HAML, you can specify option
:ugly
to instruct it to not indent your generated html.More informations in documentation.
Id don't know about any setting for erb, but from my understanding, erb doesn't format your code, you format if. If you want to not indent your html, you should write it as such (or preprocess your erb templates before deploying)