How to Avoid HTML in JavaScript [closed] - javascript

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I have a lot of elements that are created on the fly from data received on the server, as JSON. To create these elements a lot of HTML is going inside my JavaScript code. Is there any solution to this problem? The JavaScript code is polluted and writing HTML tags becomes harder and less maintainable.

Templating tools such as handlebars, mustache and dust.js were designed to solve this very problem.

Ember.js is another alternative that allows you to remove HTML from your JavaScript through their templating tool called HTMLBars.
Check it out!

Related

Is there any node modules or any system that removes Unused CSS to Reduce the Size of Style-sheets? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I want to remove all of the unused CSS classes from my stylesheet before I push my project to the server! But I don't find any shortcut way to do that.
It depends on how complex your project is and what way to usage classes in markup it is using. For simpler ones, something from the tools listed here can be helpful https://www.keycdn.com/blog/remove-unused-css. If your project is more complex, and if classes are created in the JS part on the flight, and then used, there might be no way to do clean up automatically

How does soundcloud generate their html? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
Today I was inspecting the soundcloud source-html through chrome, but it only returned a basic(very small) html dom.
So I was wondering how do they generate their html?
I'm curious because soundcloud is a pretty big website and I doubt they generate all the html though javascript, but when I checked their javascript I could not find any <div tags or anything like that.
For larger dynamic websites usually a template framework is used like EJS - http://www.embeddedjs.com/
With templating you can embed JavaScript logic directly into the HTML so it changes and updates dynamically.

Create Html template document from Javascript and Php variables [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I am developping an application. As final result the application generates a Html document consisting of variables from external Javascript and Php files.Which is the safest way to pass these variables?.
Thank you very much.
You can use AJAX to do this, you make the request in JS, and process the information in PHP(server side), and you can return an JSON Object with the variables, or simply, return the HTML code and output it.
Hope it helps :D

How to transfer JavaScript variables to PHP [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I've got a problem. I don't know how to transfer JS variables to PHP.
In JS I've got my main script and I'm using PHP only to file management but I need some variables from JS.
The short answer is AJAX, (or SOAP but you better go with AJAX). So go do a little research on it, and if you know jQuery or Prototype or something similar, you are pretty much off for starting to code in a new technology in minutes.
Here are some links, to get you started:
How to start learning Ajax?
http://api.jquery.com/jquery.ajax/

What is the difference between EJS and underscore.js' .template() [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
Both seem to be doing very similar things, in a similar way.
Both let you embed javascript into the templates, and have the same 3
types of tags -unescaped replace, escaped replace, embed js-.
Both have the ability to 'precomile' the template by creating the
generator function.
Also, both can be used as the template engine
for express/node.js. (and in the browser, and everywhere else that supports js).
So when having to choose beween EJS and underscore.js templates: what things should be taken into account? Are they the same thing with just different name? If this is the case, why is it that there are 2 template engines so similar?

Categories

Resources