views:

30

answers:

1

I've been trawling SO for a couple of hours tonight looking for some answers, but I've not found anything that really answers what I'm after. My apologies if it has, in fact, been answered already.

I'm designing a new website and I'm trying to decide on the architecture to use to serve the content. In the past, my websites have used PHP feeding data into Smarty templates.

However, recently at my work, I've been working on a Java web application where jQuery was used to retrieve the data from a RESTful API (which returned JSON), where HTML template pages were used as the base and javascript was used (utilising jQuery) to fill in the content.

My question:

The website I'm designing will be in PHP, but would it be better to construct (or use an existing) RESTful API or to continue on as I've done before feeding the data into Smarty templates?

Are there real benefits to one or the other, or does it just come down to developer preference/experience?

If it helps, the website will be for a church, where the content types will be CMS-like; news/announcements, wiki-like pages, and a limited type of social networking (for the minister to communicate with parishioners).

+1  A: 

Short answer: It sounds like filling the content with JavaScript would not be useful in your case. Loading the data with JavaScript is adding a layer of complexity with minimal or no benefit (in your case). Take a look at CMSs and websites that have similar functionality to what you're doing. WordPress, Drupal, etc.

For an example of when it might be useful to load data with JavaScript, check out the tags section on this site. When you search for a tag it queries the server without reloading the page. However, the initial tag list is loaded during the initial page load without any JS.

Here are some cases where you might benefit from loading information with JS:

  • There is some data that will take longer to load. For example, you're getting data from a web service. Using the traditional method, you would need all the data you need for the page to be available before it can be displayed. If you loaded that data with JavaScript, the page could load and the slow data would appear when it returns. Realistically, you would probably just cache the data but this is just an example.
  • You will be getting more data as the user stays on the page. You might want to update the page without refreshing.
  • You want the user to be able to query more data without refreshing the page.
  • Your users have limited bandwidth (mobile).
  • This site has more guidelines: http://www.oracle.com/technetwork/articles/javase/index-137171.html
Uriah
Thanks for your answer. It sounds like that the RESTful functionality would be better suited as a supplementary feature, assisting in UI and navigational assistance, rather than the main content delivery?
Cyntech
Yeah, that's my opinion on the subject for the majority of web sites. Every application is different though. Gmail is an example of a web app that loads pretty much all the content via Ajax.
Uriah