Is there a way to minimalize HTML content?
For example, let's say I have a regular HTML document such as:
<html>
<title>A title or something</title>
<h2>Blah blah blah times 5 </h2>
<p>
Blah blah blah times 5Blah blah blah times 5Blah blah blah times 5Blah blah blah times 5Blah blah blah times 5Blah blah blah times 5Blah blah blah times 5Blah blah blah times 5Blah blah blah times 5Blah blah blah times 5Blah blah blah times 5Blah blah blah times 5Blah blah blah times 5Blah blah blah times 5
</p>
</html>
I would rather if possible do something like this:
<html>
<title>{title of page}</title>
<h2>{header information}</h2>
<p>
{Paragraph information}
</p>
</html>
I'm not sure how the html page would know it's getting that information but I'm looking just to see if this is possible or not.
You probably want to use a library like Handlebars. There are other similar libraries out there as well so take care to research which is best for you.
Handlebars will allow you to use the {{something}}
format to minimise the information you code into your html. Others will use a similar, if not the same, format.
Building on that, you could also switch to using an MVC framework (such as Angular or Ember) which include similar "mustache" style templating and other helpful features in order to make your dynamic content easier to code. Ember actually uses Handlebars, Angular uses it's own "directives" which are very similar. Other MVC frameworks with included templating are available as well.
You're basically asking about using some kind of UI templating framework. It's possible to do, it can be done server-side or client-side, each has it's pros and cons.
Since you tagged the question with javascript
and jquery
here are a few client-side templating frameworks that you may find useful:
Also take a look at Template Engine Chooser
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With