Dynamically Built Interface
What you are seeing are websites whose interfaces are fully or partially built using JavaScript, that is, code that runs in your browser.
Usually you get very basic HTML when you access the page, plus a set of data, plus some scripts.
Later, more data can be loaded over time into asynchronous requests using Ajax.
What is the purpose
This kind of technique runs somewhat out of web standards, and is generally adopted to improve the user experience, not making it wait for page load after page.
This gives the feel of using a conventional program rather than a web site.
Problems
On the other hand, developing web applications of this type is more laborious and error prone.
Examples
Single page applications (single-page applications) on its own generally adopt this type of strategy.
This is the case, for example, in Gmail. It loads all the code and necessary structures as soon as you access it. You can then perform a series of tasks without transferring server data.
In general Google applications, there is even partial support for working offline.
How this is done in practice
In general there are two strategies for dynamic element generation:
Creating elements programmatically
Dog created instances of objects that represent HTML tags and then they are added somewhere on the page.
This is done with the createElement
JavaScript function. Example:
//cria tag <p>
var minhaDiv = document.createElement("p");
//adiciona um texto
var conteudo = document.createTextNode("Olá!");
minhaDiv.appendChild(conteudo);
//adiciona tag na página
document.body.appendChild(minhaDiv);
Creation based on an HTML template
You can also inject a piece of HTML code somewhere on the page.
This can be done by using the innerHTML
attribute element on the page. Example:
//substitui todo o conteúdo da página por "Olá"
document.body.innerHTML = "Olá";
There is some difference in performance between the two forms, but in the end the result is the same.