HTML引用的ASP.NET应用程序性能

时间:2022-08-26 20:23:42

Quick question regarding scripts and html.

关于脚本和HTML的快速问题。

In a html file, would there be a difference speed wise (although it might be minor) in the following two examples if I included a JavaScript script using:

在一个html文件中,如果我使用以下两个示例包含JavaScript脚本,那么在以下两个示例中是否会有明显的差异(尽管可能会很小):

<script src="http://localhost:56090/Scripts/jquery-2.1.4.js"></script>

and

<script src="~/Scripts/jquery-2.1.4.js"></script>

The first one includes a script from a different project in the same ASP.NET solution, whereas the second one uses a script from the same project as the html file.

第一个包含来自同一ASP.NET解决方案中不同项目的脚本,而第二个脚本使用与html文件相同的项目中的脚本。

What would be the difference?

有什么区别?

On a side note (but kind of related), how do the projects of a solutions relate to each other, are they compiled into a single application domain or are they separate applications but linked to each other?

在旁注(但有点相关),解决方案的项目如何相互关联,它们是编译成单个应用程序域还是它们是单独的应用程序但是相互链接?

Many thanks :)

非常感谢 :)

2 个解决方案

#1


0  

Client-side there is zero difference. Both get emitted to fully-qualified URLs (possibly even the exact same URL, depending on what ~ resolves to) and the client sees no difference between the two.

客户端存在零差异。两者都被发送到完全限定的URL(可能甚至是完全相同的URL,取决于解析的内容),并且客户端看不到两者之间的差异。

Server-side there is a tiny difference because ASP.NET needs to translate ~ into a path. That's a very optimized, very fast operation. You shouldn't notice a difference. But if you're at a scale where you really need to squeeze every millisecond possible (like, Google-scale), this adds a millisecond.

服务器端存在细微差别,因为ASP.NET需要将〜转换为路径。这是一个非常优化,非常快速的操作。你不应该注意到差异。但是如果你的规模很大,你真的需要尽可能地挤压每一毫秒(比如谷歌规模),这就增加了一毫秒。

In all likelihood you should use whichever makes the most logical sense for your application needs. The performance difference is negligible.

您很有可能应该根据您的应用需求使用最符合逻辑的理念。性能差异可以忽略不计。

#2


0  

no difference

as

<script src="~/Scripts/jquery-2.1.4.js"></script>

is compiled into the correct string...

被编译成正确的字符串......

The view is compiled anyway regardless of the ~

无论如何都会编译视图

The the difference in time is basically unmeasureable in c#... so you wouldn't be able to tell using convention tools if there was actually a difference.... we are probably talking about nanoseconds here or smaller.

时间上的差异在c#中基本上是不可测量的...所以如果实际存在差异,你将无法使用约定工具告诉....我们可能在这里或更小的时候讨论纳秒。

so its better to use

所以它更好用

<script src="~/Scripts/jquery-2.1.4.js"></script>

than hard coding any values.

而不是硬编码任何值。

Advantage is that the base url is dynamic/relative to what the site is. i.e. if you hard coded localhost... you are going to have Huge issues when you try and deploy this to an actual url. e.g. www.mycoolwebsite.com

优点是基本网址是动态的/相对于网站的内容。即如果您硬编码localhost ...当您尝试将其部署到实际URL时,您将遇到巨大问题。例如www.mycoolwebsite.com

#1


0  

Client-side there is zero difference. Both get emitted to fully-qualified URLs (possibly even the exact same URL, depending on what ~ resolves to) and the client sees no difference between the two.

客户端存在零差异。两者都被发送到完全限定的URL(可能甚至是完全相同的URL,取决于解析的内容),并且客户端看不到两者之间的差异。

Server-side there is a tiny difference because ASP.NET needs to translate ~ into a path. That's a very optimized, very fast operation. You shouldn't notice a difference. But if you're at a scale where you really need to squeeze every millisecond possible (like, Google-scale), this adds a millisecond.

服务器端存在细微差别,因为ASP.NET需要将〜转换为路径。这是一个非常优化,非常快速的操作。你不应该注意到差异。但是如果你的规模很大,你真的需要尽可能地挤压每一毫秒(比如谷歌规模),这就增加了一毫秒。

In all likelihood you should use whichever makes the most logical sense for your application needs. The performance difference is negligible.

您很有可能应该根据您的应用需求使用最符合逻辑的理念。性能差异可以忽略不计。

#2


0  

no difference

as

<script src="~/Scripts/jquery-2.1.4.js"></script>

is compiled into the correct string...

被编译成正确的字符串......

The view is compiled anyway regardless of the ~

无论如何都会编译视图

The the difference in time is basically unmeasureable in c#... so you wouldn't be able to tell using convention tools if there was actually a difference.... we are probably talking about nanoseconds here or smaller.

时间上的差异在c#中基本上是不可测量的...所以如果实际存在差异,你将无法使用约定工具告诉....我们可能在这里或更小的时候讨论纳秒。

so its better to use

所以它更好用

<script src="~/Scripts/jquery-2.1.4.js"></script>

than hard coding any values.

而不是硬编码任何值。

Advantage is that the base url is dynamic/relative to what the site is. i.e. if you hard coded localhost... you are going to have Huge issues when you try and deploy this to an actual url. e.g. www.mycoolwebsite.com

优点是基本网址是动态的/相对于网站的内容。即如果您硬编码localhost ...当您尝试将其部署到实际URL时,您将遇到巨大问题。例如www.mycoolwebsite.com