开发者

ServerSide(PHP) vs. ClientSide(JS) running trade off

开发者 https://www.devze.com 2023-01-09 13:55 出处:网络
I have a collection of rows, I can generate Table(开发者_JAVA百科HTML) out of it using PHP (server side)

I have a collection of rows, I can generate Table(开发者_JAVA百科HTML) out of it using PHP (server side) or I can send the raw data to the client side and generate the Table there using JavaScript

Which one is better and way?


The server side would run faster as you do need to go over the collection of rows anyway in order to make a string out of it so instead of doing that, you better create the table already...

rendering content using JavaScript in also an anti-pattern of SEO!


Don't make site-critical functionality rely on Javascript, as this might be disabled (for people who turn it off) and would leave the data uncrawlable by web spiders (for example, Google)


It's best to avoid Javascript in this case, unless you really want every bit of processing on the client end; you will not benefit much by printing the data with JavaScript, and there we be more negative impacts, like the possibility that the end user does not support JS or certain browsers do not support your script.

Regardless the data will most likely make up the bulk of your result from what it sounds. The more important thing to decide is whether or not you will be using divs or a table, if the data is something that needs to be presented in a tabular manner, than use a table, otherwise avoid it at all costs. Having 1 div and some line breaks instead of a ton of tables/rows and cells would be a drastic reduction in load time comparatively.

It does depend exactly what you're doing though.


As the Col. said you free to choose either. However, which one of them is appropriate is depending on the task.

I think, there are quite a few things to consider when you design a web application/web site. Deciding which elements are going to be built server side - therefore relying on the resources of the server, and which should be processed on the client computer is always a crucial part of the plan.

Too many server side processes can put a significant load on the server in case of a popular web site for instance. (in some cases these processes could become defunct processes and they are a real pain)

Keeping functionality partially on client side tends to ease the load. If there are no usability (speed, browser dependence, SEO etc.) implications it is best practice.


My answer assumes you are building a web app that is not targeted at low-end browsers.

In this case, definitely client side. Even if you have 1000s of rows. Send them over in JSON (lower bandwidth req.), then render the table using jQuery, but don't display them all at once. That'll kill your browser. Use paging, sorting and search creatively to establish an optimal user experience. If you have to deal with hundreds or thousands of rows, use jOrder for search, sorting and paging to keep things fast.

0

精彩评论

暂无评论...
验证码 换一张
取 消