前端的演化Fundamentals of Web apps

发布于:2024-04-09 ⋅ 阅读:(30) ⋅ 点赞:(0)

Traditional web applications
When entering the page, the browser fetches the HTML document detailing the structure and the textual content of the page from the server. HTML Get

The server has formed this document somehow. The document can be a static text file saved into the server’s directory. The server can also form the HTML documents dynamically according to the application’s code, using, for example, data from a database. The HTML code of the example application has been formed dynamically because it contains information on the number of created notes.

It is an HTTP POST request to the server address new_note. The server responds with HTTP status code 302. This is a URL redirect, with which the server asks the browser to do a new HTTP GET request to the address defined in the header’s Location - the address notes.

The code on the server responsible for the POST request is quite simple (NB: this code is on the server, and not on the JavaScript code fetched by the browser):

AJAX (Asynchronous JavaScript and XML) is a term introduced in February 2005 on the back of advancements in browser technology to describe a new revolutionary approach that enabled the fetching of content to web pages using JavaScript included within the HTML, without the need to rerender the page.

Before the AJAX era, all of the data shown on the page was fetched with the HTML code generated by the server.

The Notes page uses AJAX to fetch the notes data. Submitting the form still uses the traditional mechanism of submitting web forms.

The application URLs reflect the old, carefree times. JSON data is fetched from the URL https://studies.cs.helsinki.fi/exampleapp/data.json and new notes are sent to the URL https://studies.cs.helsinki.fi/exampleapp/new_note. Nowadays URLs like these would not be considered acceptable, as they don’t follow the generally acknowledged conventions of RESTful APIs, which we’ll look into more in part 3.

The thing termed AJAX is now so commonplace that it’s taken for granted. The term has faded into oblivion, and the new generation has not even heard of it.

The sample app is done with so-called vanilla JavaScript, using only the DOM-API and JavaScript to manipulate the structure of the pages.

Instead of using JavaScript and the DOM-API only, different libraries containing tools that are easier to work with compared to the DOM-API are often used to manipulate pages. One of these libraries is the ever-so-popular jQuery.

jQuery was developed back when web applications mainly followed the traditional style of the server generating HTML pages, the functionality of which was enhanced on the browser side using JavaScript written with jQuery. One of the reasons for the success of jQuery was its so-called cross-browser compatibility. The library worked regardless of the browser or the company that made it, so there was no need for browser-specific solutions. Nowadays using jQuery is not as justified given the advancement of JavaScript, and the most popular browsers generally support basic functionalities well.

The rise of the single-page app brought several more “modern” ways of web development than jQuery. The favorite of the first wave of developers was BackboneJS. After its launch in 2012, Google’s AngularJS quickly became almost the de facto standard of modern web development.

However, the popularity of Angular plummeted in October 2014 after the Angular team announced that support for version 1 will end, and that Angular 2 will not be backwards compatible with the first version. Angular 2 and the newer versions have not gotten too warm of a welcome.

Currently, the most popular tool for implementing the browser-side logic of web applications is Facebook’s React library. During this course, we will get familiar with React and the Redux library, which are frequently used together.

The status of React seems strong, but the world of JavaScript is ever-changing. For example, recently a newcomer - VueJS - has been capturing some interest.

React是由Facebook开发并且开源的UI库,换言之,其专注于完成将数据渲染到HTML这一步骤,也就是所谓的View层

在这里插入图片描述