tags:

views:

123

answers:

5

I have a collection of rows, I can generate Table(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?

+11  A: 

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!

MrOhad
+6  A: 

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)

Gareth
I'm interested to know why this was downvoted - would be nice to know what was disagreed with
Gareth
probably an ignorant developer like there are so many. the answe´r is exactly one thing: correct.
TomTom
+2  A: 

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 fuctionality partially on client side tends to ease the load. If there are no usability (speed, browser dependance, SEO etc) implications it is best practice.

G Berdal
+2  A: 

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.

A: 

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.

Dan Stocker
-1.... because at the end you do not really say what you LOOSE, and that is a lot. Legal requirements in accessibility AND.... any search engine crawling of your content. Gratulations.
TomTom
If this is static content we're talking about, then you are right. But I don't see that mentioned in the question.
Dan Stocker
Content has to be pretty damn dynamic (i.e. generated upon a JS request) to justify rendering on the client side. Doesn't say it is in the question, so it's better to be safe and actually mention this. Assumptions are bad.
You
@You: right on. I wonder though how often do the others come across table structured data (a report for instance) that has to be crawled.
Dan Stocker