0

Just as JSON is a light and simple alternative to XML for data transmission and other uses, is it possible to create an alternative for HTML and that it is natively interpreted by the browser?

For example, the following codes displays the message: Hello World.

HTML:

<div id="mydiv" class="myclass">
    <span>Hello World</span>
</div>

Alternative HTML:

div #mydiv .myclass
    span >Hello World

Comparison:

  • HTML: 68 characteres.
  • Alternative HTML: 41 characteres.
  • The Alternative HTML has approximately 40% fewer characters.

Some preprocessors already have a syntax that could be taken as a reference, such as: http://haml.info

Maybe I don't know the complexity, the scope or if this has already been evaluated, but my question is if there are reasons not to create the Alternative HTML.

alditis
  • 4,633
  • 3
  • 49
  • 76

4 Answers4

1

Something similar actually exists, it's called pug. But it needs to be pre-processed. If it could be interpreted natively by the browser it would be great !

1

Just as JSON is a light and simple alternative to XML for data transmission and other uses.

JSON and XML are good at significantly different things. XML was a bad fit for many things it was used for before JSON was available. XML is still a good fit for the things XML is good at.

Is it possible to create an alternative for HTML and that it is natively interpreted by the browser?

No.

You could write an alternative and then process it with client-side JavaScript.

The Alternative HTML has approximately 40% fewer characters.

If you care about the amount of data you are transmitting, then use HTTP compression.

You aren't going to see significant gains by trying to trim out a few bytes of HTML.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
  • My intention is not to add tasks to the client (browser) but quite the opposite. I think a decrease in data load is always welcome (Compressing something light will be lighter). Although there are also other aspects to consider such as ease of development and maintenance, one symptom that can be improved is that there are several html preprocessors. – alditis Jun 25 '20 at 16:51
1

but my question is if there are reasons not to create the Alternative HTML

Having created in 1990, I'm sure HTML has lot of potential for improvement. However, technology is intertwined with Business while both feeding each other. In this context, answers to the following questions might answer your original question.

  1. Will the compatibility overhead of an alternative HTML outweigh its benefits?

  2. Is it worth the effort in an environment that HTML works well for the needs of the foreseeable future?

  3. Will improved HTML still give performance and resource benefits if still operated on the conventional protocols such as HTTP?

Good news It will happen

Bad news Not soon

Charlie
  • 22,886
  • 11
  • 59
  • 90
  • 1.) and 3.) If the alternative HTML were JSON, it would have the advantages that JSON has over XML (ex: simple and lightweight). Do you remember when you saw html the first time? Also, if the content of a website can be transmitted using JSON. Why can't the structure also be sent in the same format? JSON has no problems with conventional HTTP. Finally JSON is replacing XML in different areas (not in all). 2.) Ok, HTML works fine, but an alternative html might work better. The foreseeable future tends to be short term, and sometimes we have surprises. – alditis Jun 25 '20 at 18:26
  • It should be profitable to someone. Thats the main part. We all like improvements as developers. But business owners need profit alongside. – Charlie Jun 25 '20 at 18:55
-1

Another thing you can do is use PHP, your code will have fewer lines, and for example the nav-bar you can store in another .php file and use the include_once comand. in order to insert that section of code in your web page. the cool thing about using php is that although, your file is saved as .php your web browser will undertand the parts of code that are in html.

I used in the past php to creat arrays with data of products that i wanted to display in my page. And then converted into a Json file.

There are built in function in PHP to manage Json file types.