简体   繁体   English

加速 ASP.Net 网站或应用程序

[英]Speeding up an ASP.Net Web Site or Application

I have an Ajax.Net enabled ASP.Net 2.0 web site.我有一个支持 Ajax.Net 的 ASP.Net 2.0 网站。 Hosting for both the site and the database are out of my control as is the database's schema.站点和数据库的托管以及数据库的架构都不受我的控制。 In testing on hardware I do control the site performs well however on the client's hardware, there are noticeable delays when reloading or changing pages.在硬件测试中,我确实控制了站点的性能,但是在客户端的硬件上,重新加载或更改页面时会出现明显的延迟。

What I would like to do is make my application as compact and speedy as possible when I deliver it.我想做的是让我的应用程序在交付时尽可能紧凑和快速。 One idea is to set expiration dates for all of the site's static resources so they aren't recalled on page loads.一种想法是为站点的所有静态资源设置到期日期,以便在页面加载时不会调用它们。 By resources I mean images, linked style sheets and JavaScript source files.我所说的资源是指图像、链接样式表和 JavaScript 源文件。 Is there an easy way to do this?是否有捷径可寻?

What other ways are there to optimize a .Net web site?还有哪些其他方法可以优化 .Net 网站?

UPDATE: I've run YSlow on the site and the areas where I am getting hit the hardest are in the number of JavaScript and Style Sheets being loaded (23 JS files and 5 style sheets).更新:我在网站上运行了 YSlow,我受到的打击最严重的地方是正在加载的 JavaScript 和样式表的数量(23 个 JS 文件和 5 个样式表)。 All but one (the main style sheet) has been inserted by Ajax.net and Asp. Ajax.net 和 Asp 已插入除了一个(主样式表)之外的所有内容。 Why so many?为什么这么多?

  1. Script Combining in .net 3.5 SP1 .net 3.5 SP1 中的脚本组合
  2. Best Practices for fast websites快速网站的最佳实践
  3. HTTP Compression (gzip) HTTP 压缩 (gzip)
  4. Compress JS / CSS (different than http compression, minify javascript)压缩 JS / CSS(不同于 http 压缩,缩小 javascript)
    1. YUI Compressor YUI 压缩机
    2. .NET YUI Compressor .NET YUI 压缩器

My best advice is to check out the YUI content .我最好的建议是查看YUI 内容 They have some great articles that talk about things like CSS sprites and have some nice javascript libraries to help reduce the number of requests the browser is making.他们有一些很棒的文章,讨论诸如CSS 精灵之类的东西,并有一些不错的 javascript 库来帮助减少浏览器发出的请求数量

If you are using Firefox to test your website, you might want to try a nifty Firefox extension from Yahoo!如果您使用 Firefox 来测试您的网站,您可能想尝试来自 Yahoo! called YSlow .称为YSlow

It analyzes your web pages and provides grades from AF (A being the Best and F being the worst) for each of the best practices, for high performance websites.它会分析您的网页,并为高性能网站的每个最佳实践提供 AF 等级(A 是最好的,F 是最差的)。 It will help you to track down the elements of your website which you could optimize to gain speedups.它将帮助您跟踪您可以优化以获得加速的网站元素。

UPDATE更新

Now YSlow extension is compatible with all modern browsers such as Firefox, Chrome, Opera, Safari and others, read more here .现在YSlow扩展与所有现代浏览器兼容,如 Firefox、Chrome、Opera、Safari 等,请在此处阅读更多内容。

默认情况下关闭视图状态,即使是最简单的页面也会有白天和黑夜的差异。

I wrote a blog post about improving ASP.NET page performance this a couple months back.几个月前,我写了一篇关于提高 ASP.NET 页面性能的博客文章 Here are some quick & easy ways -这里有一些快速简便的方法 -

  • Turn off view state关闭视图状态
  • Turn off event validation关闭事件验证
  • Implement HTTP gzip/deflate compression to reduce the response size (number of bytes the server has to send back to the client)实现 HTTP gzip/deflate 压缩以减少响应大小(服务器必须发送回客户端的字节数)
  • Try to optimize/minimize your database calls for each request尝试优化/最小化每个请求的数据库调用

I think you really need to be able to get some actual PerfMon data/telemetry from the app whilst running in production to be able to make an enlightened decision about what to optimise.我认为您确实需要能够在生产中运行时从应用程序中获取一些实际的 PerfMon 数据/遥测数据,以便能够就优化内容做出明智的决定。

As a throw away tip I'd make sure your app is deployed as a Release build and set debug="false" in the ' compilation ' section of your web.config.作为一次性提示,我会确保您的应用程序部署为发布版本,并在您的 web.config 的“编译”部分中设置 debug="false"。

You seem to be starting by assuming that your problem is download size - that may not necessarily be the case.您似乎开始假设您的问题是下载大小 - 情况可能不一定如此。 You should do some experimentation with your ASP.NET site to determine if there are areas in your code which are causing undue delays.您应该对您的 ASP.NET 站点进行一些实验,以确定您的代码中是否存在导致过度延迟的区域。 If it turns out that download size is not your problem, you'll need to find ways to cache your results (look into output caching, which is an ASP.NET feature) or optimize your code.如果事实证明下载大小不是您的问题,您将需要找到缓存结果的方法(查看输出缓存,这是 ASP.NET 功能)或优化您的代码。

In any case - the first step when looking at a performance issue is always to verify your assumptions first, then decide on a course of action.在任何情况下 - 查看性能问题的第一步总是首先验证您的假设,然后决定行动方案。

A general thing when using ASP.NET and Ajax (any Ajax library) together is to avoid elephanting your Page_Load and Page_Init (and their method counterparts) things since these will be executing on every Ajax Request.将 ASP.NET 和 Ajax(任何 Ajax 库)一起使用时,一般的事情是避免将 Page_Load 和 Page_Init(以及它们的方法对应物)事情变得复杂,因为它们将在每个 Ajax 请求上执行。

When that is said I would seriously ditch ASP.NET AJAX and use anything else...当我这么说时,我会认真地放弃 ASP.NET AJAX 并使用其他任何东西......

Anthem.NET, AjaxPRO.NET, jQuery or whatever else than ASP.NET AJAX... Anthem.NET、AjaxPRO.NET、jQuery 或 ASP.NET AJAX 以外的任何东西......

Of course I would use Ra-Ajax myself since that's my project.当然,我自己会使用Ra-Ajax,因为那是我的项目。 But then again I am biased...但话又说回来,我有偏见......

You could start looking at caching strategies.您可以开始研究缓存策略。 Static files like CSS (even compressed ones) and images (even optimized ones) should only need to be downloaded once by the browser for a period of time.像 CSS(甚至是压缩的)和图像(甚至是优化的)这样的静态文件应该只需要在一段时间内被浏览器下载一次。

Scirpt combining for AJAX has already been mentioned, but I didn't notice reference to the ScriptReferenceProfiler MS has released on codeplex to help figure out what to combine.已经提到了 AJAX 的 Scirpt 组合,但我没有注意到参考 ScriptReferenceProfiler MS 已在 codeplex 上发布,以帮助确定要组合的内容。 Mike Ormond has a good start point on this . Mike Ormond 在这方面有一个很好的起点

Another tip if you're doing a lot of INSERTs to your database is to double check your server's disk caching is switched on.如果您对数据库执行大量 INSERT,另一个提示是仔细检查服务器的磁盘缓存是否已打开。 Case in point, I had an data importer doing 1.2 million inserts during a run.举个例子,我有一个数据导入器在运行期间执行 120 万次插入。 Took 4 hours and change without caching on.花了 4 个小时,在没有缓存的情况下进行了更改。 Took 16 minutes with it on.用了 16 分钟。

You could turn on compression based on your client supporting it.您可以根据支持它的客户端打开压缩。 See this article: link text看这篇文章: 链接文字

Static resources shouldn't be resent unless changed.除非更改,否则不应重新发送静态资源。 IIS will send a response code which tells the browser to use the cached version. IIS 将发送一个响应代码,告诉浏览器使用缓存版本。

You could also look at ASP.NET output caching, which can be applied fairly granularly to different portions of your page:您还可以查看 ASP.NET 输出缓存,它可以相当精细地应用于页面的不同部分:

http://msdn.microsoft.com/en-us/library/xsbfdd8c(VS.71).aspxhttp://msdn.microsoft.com/en-us/library/xsbfdd8c(VS.71).aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM