views:

56

answers:

4

We have an HTML page with multiple div blocks. We want to separate these div's into multiple files and then combine them all together into a single file - is it best to use server side includes (JSP in our case) or client side includes?

Note that we're using JQuery - not sure if JQuery has a clever way to do the includes.

A: 

I would say server side. What about, if jQuery doesn't load, or the user has javascript turned of?

Mike
+1  A: 

In terms of performance it is vastly superior to do this kind of processing on the server. The costs in terms of I/O and processing for additional HTTP requests -- as would be necessary if you were doing the collation on the client -- would be significant. Including additional content on the server will result in milliseconds of delay for the user; doing it on the client will take orders of magnitude more.

Edit Per Luke Schafer's comment, this presumes that the content being put together can be instantly generated (e.g. by including flat files from the server). If it takes time (e.g. lengthy database calls) it might be appropriate to load the main part of the page and add extra content in with jQuery. The best solution, as ever, depends on your particular circumstances.

lonesomeday
A: 

I would do it on the server side

girdus
+1  A: 

I have to agree with everyone else that the serverside is the place, with a caveat.

If your sections contain something that takes a while to load, say, each one has content from a separate web service call, it might be beneficial to let JQuery load them for you with a get, as the rest of the page can be loaded while the sections are loaded asynchronously.

Other than that, yeah... server side

Luke Schafer
+1 I agree fully with this point and have added it as a caveat to my answer. Thanks.
lonesomeday