如何减少 ASP.NET 应用程序中的页面加载时间?

发布于 2024-09-07 14:32:26 字数 152 浏览 10 评论 0原文

如何减少 ASP.NET 应用程序中的页面加载时间?应该采取哪些预防措施,特别是当我们与数据库交互时

,例如

  1. 明智地使用视图状态
  2. 部署应用程序时在 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.

  1. wise use of viewstate
  2. Set in web.config when deploying the app

    etc

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(11

染墨丶若流云 2024-09-14 14:32:26

TechEd 2010 North America 的一些关键“要点”:

  • 缓存是性能的关键,请仔细考虑您的缓存策略。
  • 如果可能的话禁用视图状态。
  • 部署应用程序时在 web.config 中设置
  • 考虑图形和其他静态内容的 CDN 或子域。
  • 将 javascript 放在页面底部,将 CSS 放在页面底部顶部。
  • 考虑使用 CSS 精灵来制作图标和其他“小”图形。

您可以在此处观看在线会议,强烈推荐它们:

Some of the key "take-aways" from TechEd 2010 North America:

  • Caching is key to performance, consider your caching strategy very carefully.
  • Disable viewstate if possible.
  • Set <compilation debug=”false"> in web.config when deploying the app.
  • Consider CDN's or subdomains for graphics and other static content.
  • Place javascript at the bottom of the page, CSS at the top.
  • Consider CSS sprites for icons and other "small" graphics.

You can watch the sessions online here, they're both highly recommended:

愚人国度 2024-09-14 14:32:26

80% 的最终用户响应时间花在前端。大部分时间都花在下载页面中的所有组件上:图像、样式表、脚本、Flash 等。

http://developer.yahoo.com/performance/rules.html

我并不是建议忽略已提供的答案中的视图状态和数据库缓存建议。我指出,我发现更简单的更改是在 IIS 中打开 GZip 压缩,在静态元素上设置过期标头以减少服务器请求,使用 smush.it

使用 Zoompf 获取非常详细的报告,其中包含估计影响和易于实施的评级。

80% of the end-user response time is spent on the front-end. Most of this time is tied up in downloading all the components in the page: images, stylesheets, scripts, Flash, etc.

http://developer.yahoo.com/performance/rules.html

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.

何止钟意 2024-09-14 14:32:26
  1. 切勿在生产环境中在调试配置下部署 asp.net 应用程序。找出这里什么scottgu< /strong> 不得不说这一点。

  2. 使用无 Cookie 的域来提供静态资源,例如图像、脚本、样式等。每个客户端请求都与一大堆 Cookie 一起发送,在提供图片或脚本时不需要 Cookie 。因此,将这些资源托管在无 Cookie 的域上。

  3. 缩小来自服务器的脚本、样式表和 HTML 响应。删除不必要的换行符和空格可以缩短加载时间并优化带宽。

可以从此处找到许多提示。

  1. Never ever Deploy asp.net application under debug configuration on production. Find out here what scottgu has to say about this.

  2. 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.

  3. 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.

滴情不沾 2024-09-14 14:32:26
  • 尝试尽可能地最小化 ViewState 或将其保留在服务器上
  • 通过使用用户控件的输出缓存来缓存页面上的数据或部分
  • 尽可能捆绑脚本和 CSS

重构某些内容后始终进行测量,看看是否有所不同。

另请查看此处的 更多信息

格兹,克里斯。

  • Try to minimize ViewState as much as possible or keep it on the server
  • Use caching of data or portions on your page by using outputcaching of user controls
  • Bundle scripts and css as much as possible

Always measure after you refactored something to see if it makes a difference.

Also please take a look here for more information.

Grz, Kris.

云仙小弟 2024-09-14 14:32:26

您始终可以触发异步数据库操作并异步更新页面 - 例如 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.

墨离汐 2024-09-14 14:32:26

在进行任何优化工作之前,最重要的事情是指出需要优化的内容。此处可以发布数以千计的优化技巧,因此最好找到您的性能问题所在,并提出更具体的问题以帮助优化您需要的内容。您可以优化 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.

萌辣 2024-09-14 14:32:26

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

惯饮孤独 2024-09-14 14:32:26
  • 缓存尽可能多的数据库读取
  • 减少/禁用视图状态
  • 做更少的事情(如果可能)
  • Cache as much db reads as possible
  • reduce/disable viewstate
  • do less (if possible)
相守太难 2024-09-14 14:32:26
  • 使用 MS Visual Studio 2010 这有帮助
    您正在优化 .NET 代码
    更好的性能。
  • 当你
    背景中有很多图像。
  • 压缩 JavaScript 的内容
    使用 gZip 压缩器和 CSS 的文件
    通过删除空格和文件
    评论。
  • 避免 HTML 注释本身
    通过“View
    浏览器中的“源”选项,其中
    也将减少文件大小。
  • 把大部分不必要的
    JavaScript 位于页面底部。
    为了更好的性能 动态
    之后加载 JavaScript 引用

    在您的页面上加载内容。
  • Use MS Visual Studio 2010 which helps
    you in optimizing your .NET code for
    better performance.
  • CSS sprites are very useful when you
    have a lot of images in background.
  • Compress the contents of JavaScript
    files using gZip compresser and CSS
    file by removing white spaces and
    comments.
  • Avoid HTML comments as they are
    visible to client side by "View
    Source" option in browser, which
    will also reduce the file size.
  • Put most of the unnecessary
    JavaScript at the bottom of the page.
    For better performance dynamically
    load the JavaScript references
    after
    loading contents on your page.
沫雨熙 2024-09-14 14:32:26

始终使用请求在应用程序中加载概念。尽量避免页面加载时不必要的数据库命中。如果页面加载时有大量数据,则可以使用 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.

独享拥抱 2024-09-14 14:32:26

以下信息用于减少页面加载时间

  1. 在托管网站时删除不需要的行空间。
  2. 将所有内联 css 文件合并到一个通用 .css 文件中。
  3. 将所有内联 Java 脚本合并到一个通用 .js 文件中,并在需要时添加对此文件的引用。
  4. 使用压缩 Javascript 和 CSS 文件。
  5. 尝试在网页中使用较少尺寸的图片。

This below information used to decrease the page load time

  1. Remove unwanted line space while hosting site.
  2. Merge all inline css file into one common .css file.
  3. Merger all inline Java scripts into one common .js file and add reference to this file whenever you require.
  4. use compress Javascript and CSS files.
  5. Try using less images with less size in your web page.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文