yask yask - 1 year ago 95
Javascript Question

Is it okay to write HTML code in Javascipt?

I wanted to create a Single page App without using front-end frameworks, since it was a small project.

So when user clicks on navigation, it fires an AJAX call and appends (HTML code with formatted data) it to HTML.

This is how it looks: https://gist.github.com/yask123/c786f49c7118e4cd91eab5c56f69257d

Is it super bad practice to do so ? Or should I use Handlebar.js just for this ? (Would it be an overkill just for one thing ..? )

Live app: http://dtumart.com/

Answer Source

It is okay to write code in your logic (JavaScript).

Loading an entire framework/library for a single action is usually overkill and there can be several benefits to creating your code in the logic.

The only real concern here is if your JavaScript fails, or the clients browser doesn't support, then the client won't see anything.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download