当前位置: 动力学知识库 > 问答 > 编程问答 >

c# - Which is faster, client side or server side dom appending?

问题描述:

In an asp.net mvc3 view, I have a $.get() ajax call to a controller action which returns 80 lines of html code. Is it faster (from the .get call to finished rendering) to do the dom element creation on server side then just pass in one huge element to be appended to the DOM, or is it faster to just pass in a lot of raw data to the client side and then do all the DOM creation and appending there?

The html returned (or generated) creates a dashboard with about 5 layers of nested divs, some spans, text, etc.

网友答案:

I suggest you do your own benchmarks because this depends on a lot of factors, like your audience device (computer/mobile), internet speeds, data plan etc. Know your target audience first and do what's better.

Returning formatted HTML is heavy on the traffic, but allows you to append it directly to the DOM. This is fine for people on a laptop/desktop who have broadband.

Returning raw data is faster but will make you create the DOM on the spot. However, this is usually ideal on high powered machines or mobile devices who have contracts whose payments are based on the amount of data transferred.

网友答案:

The major CPU work done in both methods is parsing HTML, generating DOM and painting it on the screen. Preparing the response on the server doesn't escape this. You cannot create DOM on the server or do this work on the server.

So the question is string concatenation on the client vs string concatenation on the server AND sending it over a network. It's kind of a no-brainer.

分享给朋友:
您可能感兴趣的文章:
随机阅读: