Why do my ASP.NET pages render slowly when placed on the server?

前端 未结 7 433
忘了有多久
忘了有多久 2021-01-27 07:43

I have a simple aspx page with a GridView control. I\'m loading the GridView with search results after the click of a button. Everything works, but the HTML rendering on the bro

相关标签:
7条回答
  • 2021-01-27 08:00

    If you need ViewState on the control, you can reduce the ViewState impact the GridView has on the page by disabling the ViewState on each row in the PreRender event:

      Private Sub grid_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles grid.PreRender
    
        For Each item As DataGridItem In grid.Items
          item.EnableViewState = False
        Next
    
      End Sub
    
    0 讨论(0)
  • 2021-01-27 08:02

    Since the network is the bottleneck in this case, try to minify the resulting HTML. Apparently, the weight of each grid row is about 640 bytes on average (2500 records generate 1.6M payload). See if you can reduce it by removing unnecessary spaces and shortening any HTML elements IDs. Move styling, if any, from the grid to CSS, as was suggested before. If grid renders any URLs (e.g. “href” in anchors or “src” in images) try to shorten them. Also, if HTML rendered by GridView is not optimal see if you can render yourself. In order to estimate the anticipated page response time in production, factor-in your average user network speed (that may be different from the network speed of your machine).

    If none of the above produce satisfactory result you may check the solution that we have – ASP.NET accelerator called Web Stimulus. It partially executes ASP.NET page code on the client to render the HTML on the client computer. Typical traffic reduction is 10-20 times with minimal code change.

    0 讨论(0)
  • 2021-01-27 08:07

    Some simple suggestions, turn off the view state on that control. Also are you using MS AJAX, that can also cause problems. Take it out of the update panel if you are.

    0 讨论(0)
  • 2021-01-27 08:14

    In short, do custom paging, so that it won't load all items on page load. Linq Data Source does it for you.

    0 讨论(0)
  • 2021-01-27 08:16

    Why don't you want to use paging? 1.6 MB is a lot for the html of a page.

    Considering you already disabled viewstate, look into reducing the amount of html by:

    • Remove unnecessary columns
    • Use only css to style the gridview. The idea being not to repeat the same visual rules all over the HTML.
    • Avoid unnecessary markup in the columns. Look into any template columns you may have, and simplify the HTML in there (also using css to style it).
    0 讨论(0)
  • 2021-01-27 08:21

    If you're not already compressing the HTTP Response, you should look into doing that.

    • Look at Yslow for FireFox (start here)
    • Compress your response with standard gzip/deflate compression
    • Do what you can to reduce the amount of data in your GridView. Elminate unecessary columns, etc.
    • Turn off viewstate
    • Use jsmin to reduce the size of your JavaScript files (if any)
    • Reduce the size of your CSS (if any)
    0 讨论(0)
提交回复
热议问题