In principle, every website is built based on 3 technologies; HTML, CSS and Javascript. HTML deals with the ordering of the different component parts of the site, CSS with the way in which those parts are rendered and javascript complex tasks such as responding to user actions.
En previous articles We had explained that it was a CSS framework and given a list of the best that we can use in Linux. How the role of Javascript is a bit more difficult to explain, we are going to make a small introduction to the subject, before we get to comment on its frameworks.
Javascript programming language. A little introduction
What is Javascript?
Javascript is a programming language originally created to stop web pages from being static, although today its use has spread to sectors that have nothing to do with the web.
Lprograms written in Javascript are called scripts and they run inside a virtual machine known as a Javascript engine.
All modern browsers include their version of the Javascript engine
For the safety of users, different browsers put limits on what Javascript code can do. For example, access to critical files on the disk. However, this can be further limited in the configuration options of each one.
The operation of the Javascript code within a web page is as follows:
- The Javascript engine embedded in the browser reads the code.
- The code is converted to machine language.
- The machine executes the code.
Being a programming language, Javascript can perform tasks like these:
- Store information within variables.
- Handle text strings.
- Run programs responding to events like clicking a link.
Javascript capabilities increase through the use of Application Programming Interfaces (APIs)
APIs are program libraries created for specific tasks that free the developer from having to rewrite existing code. In the case of Javascript we can talk about two types of APIS
Browser APIs
They run inside the browser and respond to the environment. We have, for example:
Document Object Model (DOM): It makes it possible to make modifications to the HTML and CSS code of the page in response to certain events. This is the case of websites that allow us to see how a page would appear on different devices.
Geolocation APIa: It is used to detect the user's location and respond accordingly. For example, it is used by Netflix to know what content you can see in your country or Google Maps to show you where you are.
Canvas and WebGL: They are ideal for plotting 2d and 3d graphics
Multimedia APIs: They allow the transmission and reception of multimedia content from a web page.
Third-party APIs
The different web services try to get more users (and in some cases more information from those users to sell it) That is why create programming interfaces so developers can integrate functionalities that these services provide to external sites. This is for example the case of those web pages that allow you to register with your Google or Facebook account.
How the Javascript code works within a website
First of all, it must be clarified that each javascript script runs within its own runtime environment. There is an execution environment for each tab (if we open different sites within the same window) or for different windows if we prefer. In no case are they interrelated with each other or, as we said, with the operating system without the active intervention of the user.
First se loads the HTML code of the web page and an object model of the document is created so that it can be displayed in the browser. The items to be attached are then loaded to the page as media, images, and style sheets. Finally, the styles are assigned to the different parts of the page as determined by the style sheets.
Once all this is finished, it is when the Javascript engine starts up following the sequence mentioned above.
In our next article we go with the promised list of frameworks for Javascript.