Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Minimalizing HTML content

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.

like image 438
Snorlax Avatar asked Dec 19 '22 18:12

Snorlax


2 Answers

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.

like image 85
millerbr Avatar answered Jan 01 '23 19:01

millerbr


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:

  • mustache.js
  • Handlebars

Also take a look at Template Engine Chooser

like image 30
driangle Avatar answered Jan 01 '23 18:01

driangle