-3

I'm new to web development and I'm a bit confused as to when should I create a HTML file versus simply have a HTML template file to load all the information into it with AJAX. And the reasons why one is better than the other.

My website is similar to how Facebook groups works. Facebook groups seem to create a new HTML file whenever a new group is created. But since all of these groups have the same layout and format for the most part, why can't we simply have one HTML template and load the information of that specific group on to the page.

Can someone explain to me, which method is better and under what conditions? I'm sure the answer is it depends on the situation.

If I am to create a HTML file every time a group is created, how would I go about it? Based on this question, it seems like if a new HTML file is created. Then we should create the HTML file on the server side: Create HTML file with JavaScript

I have been looking for the past couple of hours and could not find any answers. Please direct in the right direction. Thank you!

Community
  • 1
  • 1
Alan
  • 313
  • 4
  • 14

2 Answers2

2

"Creating an html file" is a task that a server side engine completes. "Inserting values to HTML" to keep a similar layout is what a templating engine does, which sounds like what you'd like to do. "AJAX" updates on a page, are usually more simplistic updates in the context you're defining them "single, or a few element updates or value insertions. These typically occur on an event within the page, or on a document event like 'when document is ready' then do this(jQuery)."

There are differences between each of the processes in many ways. For example, AJAX can be limited by CORS and sometimes allowing cross site scripting is something you have to configure within your server. AJAX is best used within the same web application and typically is used in the front end or "browser side code" of an application.

Templating engines are typically used on the server side, with the exception of some engines like Angular, which uses a sort of "templating-functions" process with some back end and front end code to offer an all around solution. (Angular 1.0 is a pretty widely used framework for this, and it works well with jQuery which allows the use of much less complex AJAX within your page, and on the fly updates and event actions)

Lastly, I've used CMS(Content Management Systems) that pre-render your page and all the required assets, such as database calls. A CMS will take a group of files and data and send them out to the client(browser) as different pages, but those are typically mapped out and defined in the back end if you manage your own CMS, and in a dashboard if your CMS is like wordpress.

To summarize in closing, there is no one "better" way. That question is globally referential to your assets, goals, current capabilities, environment, end product, and end users. Typically a straight forwards webapp that ends up being marketable uses something like the MEAN stack, which provides you with M - MongoDB(your database) E - Express(your page server, possibly your middleware) A - Angular (your routing/templating/etc) N - NodeJS(your terminal like access to the file system and http protocols) the benefit to the MEAN stack being it's entirely JavaScript so learning all 4 specific components is much easier concurrently than it is separately.

I hope that helps, try not to ask such beginner questions at stack overflow however as you will receive many down votes on general guidance questions like this. For more information on the MEAN stack, please visit (http://mean.io/#!/) I think what you will learn there will really serve you well in creating the end product you're aiming for.

Mike Horstmann
  • 580
  • 2
  • 9
  • Thank you Mike! This is exactly what I was looking for. I just didn't understand the underlying concepts. – Alan Sep 13 '15 at 03:24
  • 1
    NP, I would recommend that you work through the "expressJS" documentation. (http://expressjs.com/) Once you feel comfortable using the basics, I'd read over in particular the "routing" section (http://expressjs.com/guide/routing.html) this will help you to understand routing and templating much better and perhaps when and why they're necessary. Express is an excellent, well supported, well written framework to understand all of the aspects you're trying to comprehend better. An additional useful tool for developing in node/express is "nodemon" (http://nodemon.io/) – Mike Horstmann Sep 13 '15 at 13:18
1

Essentially, what IS happening is that they MIGHT be using an HTML template.

However, data is being interpolated on the server-side (Read on Template Engine). This allows a rough-skeleton of the dynamic page, which can further be customized on the client-side using client scripting language (Example: JavaScript).

Talking about which method is better (Server side rendering vs Client side rendering) - Read this question on programmer exchange

Community
  • 1
  • 1
Vageesh Bhasin
  • 553
  • 2
  • 12