如何减少 ASP.NET 应用程序中的页面加载时间?
如何减少 ASP.NET 应用程序中的页面加载时间?应该采取哪些预防措施,特别是当我们与数据库交互时
,例如
- 明智地使用视图状态
部署应用程序时在 web.config 中设置
etc
How to decrease the page load time in ASP.NET application? What should be the precautions and specially when we are interacting with databases
e.g.
- wise use of viewstate
Set in web.config when deploying the app
etc
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(11)
TechEd 2010 North America 的一些关键“要点”:
。您可以在此处观看在线会议,强烈推荐它们:
Some of the key "take-aways" from TechEd 2010 North America:
<compilation debug=”false">
in web.config when deploying the app.You can watch the sessions online here, they're both highly recommended:
我并不是建议忽略已提供的答案中的视图状态和数据库缓存建议。我指出,我发现更简单的更改是在 IIS 中打开 GZip 压缩,在静态元素上设置过期标头以减少服务器请求,使用 smush.it
使用 Zoompf 获取非常详细的报告,其中包含估计影响和易于实施的评级。
I'm not suggesting ignore the view state and database caching suggestions in the answers already provided. I'm pointing that for what I've found to be simplier alterations is to go for turning on GZip Compression in IIS, setting expiry headers on static elements to reduce server requests, optimize images using a tool such as smush.it
Run a report of your site using Zoompf for a very detailed report with estimate impact and easy of implementation ratings.
切勿在生产环境中在调试配置下部署 asp.net 应用程序。找出这里什么scottgu< /strong> 不得不说这一点。
使用无 Cookie 的域来提供静态资源,例如图像、脚本、样式等。每个客户端请求都与一大堆 Cookie 一起发送,在提供图片或脚本时不需要 Cookie 。因此,将这些资源托管在无 Cookie 的域上。
缩小来自服务器的脚本、样式表和 HTML 响应。删除不必要的换行符和空格可以缩短加载时间并优化带宽。
您可以从此处找到许多提示。
Never ever Deploy asp.net application under debug configuration on production. Find out here what scottgu has to say about this.
Use Cookie-less domains to serve static resources like images, scripts, styles etc. Each client request is sent along with whole bunch of cookies, you don't need cookies while serving pictures or scripts. So host those resources on a cookie-less domain.
Minify scripts, stylesheets and HTML response from the server. Removing unnecessary line-breaks and white-spaces can improve the time-to-load and bandwidth optimization.
You'll find many tips from here.
重构某些内容后始终进行测量,看看是否有所不同。
另请查看此处的 更多信息。
格兹,克里斯。
Always measure after you refactored something to see if it makes a difference.
Also please take a look here for more information.
Grz, Kris.
您始终可以触发异步数据库操作并异步更新页面 - 例如 AJAX 更新面板。
还有页面输出缓存,如果页面大部分是静态的,则很有用。它还可以基于参数来完成,因此您可以缓存为给定数据库搜索创建的页面。
您还可以采取过度的方法并减少页面的“冗长”。我曾经在产品页面上这样做过一次,通过缩小元素名称等来好玩,成功地减少了 50% 的页面大小,但它使标记完全不可读哈哈
沿着同样的路线,将缩减工具应用于 css/javascript 文件 -如果您进行压缩,也可以合并它们,因为压缩对于较少的大文件来说会更加有效。
You could always trigger an async database action and have the page updated asynchronously - AJAX update panel comes to mind.
There is also Page Output Caching, useful if the page is largely static. It can also be done based on parameters, so you could potentially cache the page created for a given database search.
You can also take the over-the-top approach and reduce the "wordiness" of a page. I did this once for fun on a products page by shrinking the names of elements etc, managed to cut over 50% of page size, but it makes the markup entirely unreadable lol
Along this same route, apply reduction tools to css/javascript files - merge them too if you compress as compression becomes more efficient over fewer larger files.
在进行任何优化工作之前,最重要的事情是指出需要优化的内容。此处可以发布数以千计的优化技巧,因此最好找到您的性能问题所在,并提出更具体的问题以帮助优化您需要的内容。您可以优化 Web 应用程序的 3 个部分:
服务器端性能:指出最大的瓶颈(分析器是实现此目的的一个简单选择)。优化瓶颈。当大问题仍然存在时,优化较小的问题或在不测量时间的情况下进行优化可能是浪费时间。
客户端性能:听取 yslow 或 google page speed 等工具的建议。
带宽:以尽可能少的请求量向用户发送尽可能少的数据量。
The most important thing before doing any work on optimizing, is indicating what needs to be optimized. Thousends of tips to optimize can be posted here, so it's better to find what your performance problem is, and ask a more specific question for help to optimize what you need. You can optimize 3 parts of a web application:
Serverside performance: Indicate the largest bottleneck (a profiler is an easy option to do that). Optimize the bottleneck. Optimizing smaller problems, or optimizing without measuring the amount of time can be a waste of time when the large one is still there.
Client side performance: Take the advise from tools like yslow, or google page speed.
Bandwidth: Send the smallest amount of data to the user as possible in the least amount of requests as possible.
MSDN 上有一篇有趣的文章,其中包含优化 ASP.Net 应用程序的 10 个技巧。它位于
http://msdn.microsoft.com/en-us/magazine/ cc163854.aspx
There is an interesting article on MSDN with 10 tips to optimize ASP.Net apps. Its at
http://msdn.microsoft.com/en-us/magazine/cc163854.aspx
您正在优化 .NET 代码
更好的性能。
背景中有很多图像。
使用 gZip 压缩器和 CSS 的文件
通过删除空格和文件
评论。
通过“View
浏览器中的“源”选项,其中
也将减少文件大小。
JavaScript 位于页面底部。
为了更好的性能 动态
之后加载 JavaScript 引用
在您的页面上加载内容。
you in optimizing your .NET code for
better performance.
have a lot of images in background.
files using gZip compresser and CSS
file by removing white spaces and
comments.
visible to client side by "View
Source" option in browser, which
will also reduce the file size.
JavaScript at the bottom of the page.
For better performance dynamically
load the JavaScript references after
loading contents on your page.
始终使用请求在应用程序中加载概念。尽量避免页面加载时不必要的数据库命中。如果页面加载时有大量数据,则可以使用 Ajax 请求调用。
Always use request to load concept in application. Try to avoid unwanted database hit on the page load.if you have large amount of data on page load then you can go with Ajax request call.
以下信息用于减少页面加载时间
This below information used to decrease the page load time