回复于VS&下;%=%GT; [英] Response.Write vs <%= %>

查看:112
本文介绍了回复于VS&下;%=%GT;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

记住,这轴承是为传统的ASP

这是更好的,包含Response.Write语句中,或通过与LT变量插入到HTML所有的HTML;%=%>

例如:

Which is better, all HTML contained within Response.Write Statements or inserting variables into HTML via <%= %>.
Eg

Response.Write "<table>" & vbCrlf
Response.Write "<tr>" &vbCrLf
Response.Write "<td class=""someClass"">" & someVariable & "</td>" & vbCrLf
Response.Write "</tr>" & vbCrLf
Response.Write "</table>" & vbCrLf

VS

<table>
  <tr>
     <td class="someClass"><%= someVariable %></td>
  </tr>
</table>

我主要是要求从性能上看,其中将有至少服务器的影响时,有多个变量插入?

I am mainly asking from a performance point of view in which will have the least server impact when there multiple variables to insert?

如果没有技术差异是什么是一个比其他的论据?

If there are no technical differences what are the arguments for one over the other?

推荐答案

首先,你应该寻找的最重要的因素是易于维护。你可以通过让破译一个混乱的网站,以维持其买入的金钱和时间,否则你将浪费服务器场。

First, The most important factor you should be looking at is ease of maintenance. You could buy a server farm with the money and time you would otherwise waste by having to decipher a messy web site to maintain it.

在任何情况下,也没有关系。在一天结束的时候,所有的ASP不只是执行脚本! ASP的解析器需要的页面,然后转换&LT;%=前pression%GT; 进入直接脚本调用,和HTML的每一个连续块变成一个巨大的调用的Response.Write 。所得脚本被缓存,除非在磁盘上的页面变化,这将导致高速缓存的脚本要重新计算重复使用。

In any case, it doesn't matter. At the end of the day, all ASP does is just execute a script! The ASP parser takes the page, and transforms <%= expression %> into direct script calls, and every contiguous block of HTML becomes one giant call to Response.Write. The resulting script is cached and reused unless the page changes on disk, which causes the cached script to be recalculated.

现在,过多的使用&LT的;%=%&GT; 引出了现代版的意大利面条code的:可怕的标签汤。您将不能够使磁头或逻辑的尾巴。在另一方面,过多的使用的Response.Write意味着你将永远无法看到的网页都直到它呈现。使用&LT;%=%方式&gt; 在适当的时候获得两全其美

Now, too much use of <%= %> leads to the modern version of "spaghetti code": the dreaded "Tag soup". You won't be able to make heads or tails of the logic. On the other hand, too much use of Response.Write means you will never be able to see the page at all until it renders. Use <%= %> when appropriate to get the best of both worlds.

我的第一个规则是可变文本,以静态文字。

My first rule is to pay attention at the proportion of "variable text" to "static text".

如果你只是可变文本几个地方来代替,在&LT;%=%GT; 语法是非常紧凑和可读性。然而,如在&下;%=%GT; 开始积累,它们混淆的HTML越来越多,同时在HTML掩盖的逻辑的越来越多的。作为一般规则,一旦你开始服用有关循环,你需要停止并切换到Response.Write`。

If you have just a few places with variable text to replace, the <%= %> syntax is very compact and readable. However, as the <%= %> start to accumulate, they obscure more and more of the HTML and at the same time the HTML obscures more and more of your logic. As a general rule, once you start taking about loops, you need to stop and switch to Response.Write`.

有没有其他许多硬性规定。您需要决定您的特定页面(或网页的部分)哪一个更重要,还是自然更难理解,或更容易打破:你的逻辑或你的HTML?它通常是一个或另一个(我见过数以百计的两个病例)

There aren't many other hard and fast rules. You need to decide for your particular page (or section of the page) which one is more important, or naturally harder to understand, or easier to break: your logic or your HTML? It's usually one or the other (I've seen hundreds of cases of both)

如果你的逻辑是更重要的,你应该更多的权重对的Response.Write ;它将使逻辑脱颖而出。如果HTML是更重要的,有利于&LT;%=%方式&gt; ,这将会使页面结构更为明显。

If you logic is more critical, you should weight more towards Response.Write; it will make the logic stand out. If you HTML is more critical, favor <%= %>, which will make the page structure more visible.

有时候,我不得不写两个版本,并比较它们并排方来决定哪一个更易读;这是最后的手段,但这样做,而code是在你的头脑清新,你会很高兴三个月后,当你必须做出改变。

Sometimes I've had to write both versions and compare them side-by-side to decide which one is more readable; it's a last resort, but do it while the code is fresh in your mind and you will be glad three months later when you have to make changes.

这篇关于回复于VS&下;%=%GT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆