开发者

performance implications of multiple JavaScript blocks in ASP.NET?

开发者 https://www.devze.com 2023-01-07 22:13 出处:网络
What are the performance hit or implications, if any, of: If I have multiple <script> tags on one .aspx page?

What are the performance hit or implications, if any, of:

  1. If I have multiple <script> tags on one .aspx page?

  2. Declaring variables in <script> tags of a .as开发者_Python百科px page and calling these variables from an external .js file?


Multiple <script> tags containing in-line javascript will not affect performance. Multiple <script> tags that load external javascript files will of course result in multiple requests; in this case it's better for performance to combine the external files into a single file.

Declaring variables within the page and referencing them outside is fine, although of course you need the declarations to be before the tags that load the external file. This is a common pattern for situations where you're getting the value for a javascript variable from server-side code.


There is really no inherent performance hit in running JavaScript on your page. Now, if it's a lot of really slow JavaScript, that's another story entirely. But the nature of just having it there isn't going to hurt anything.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号