Home > Backend Development > PHP Tutorial > javascript - I beg the master: How to best cooperate with the front and back ends

javascript - I beg the master: How to best cooperate with the front and back ends

WBOY
Release: 2016-08-04 09:20:45
Original
993 people have browsed it

Produce dynamic php and jsp pages with data, and the front-end and back-end packaging and publishing are completely independent.
The advantage of this is the performance of the front-end layer. The data is completely controlled by the front-end.
Any problems can be solved independently by the front-end and packaged and released separately.

The packaging and release of front-end and back-end are completely independent. The meaning and understanding of this game

Reply content:

Produce dynamic php and jsp pages with data, and the front-end and back-end packaging and publishing are completely independent.
The advantage of this is the performance of the front-end layer. The data is completely controlled by the front-end.
Any problems can be solved independently by the front-end and packaged and released separately.

The packaging and release of front-end and back-end are completely independent. The meaning and understanding of this game

The front-end and back-end are separated, the front-end is engineered, and all interactions between the front-end and the back-end are through the API. You may think that this is not good for SEO, but now with nodejs, page rendering can be left to the front-end. In fact, this is also a trend. The end-end should care about system availability, performance and other issues, and should not focus on page issues. This part should be left to the front-end.

This blog should be able to help you develop ideas for separate front-end and back-end web development by livoras

First, determine the communication protocol and communication parameters.
Front-end independent jobs can use tools such as mock to simulate background data transmission.
Back-end design uses data models to complete business and generate interfaces.
Personally, I think it is similar to separating the view business such as the template engine in PHP from the project to form an independent front-end version?

The front and back ends interact through API. It doesn't matter whether you use the web front-end or the ios and Android client.

The backend should try to use the same API to meet the needs of multiple front-end pages or even different front-ends. This is the best. The front end needs to know what data is returned by the back end and how it should be rendered according to the design diagram.

A while ago I wrote an article on the steps to develop non-native APP using ionic and cordova on the front end and CoreThink on the back end http://www.oschina.net/question/2598464_2151690?fromerr=mCRfZH2m You can take a look

Simply put, separate the front and back ends through data interfaces (such as ajax requests).

Negative case

I took over a semi-formed web project last year: it was developed in the backend PHP language. I wouldn’t know it without looking at the code. When I looked at the code, I fainted. The code is basically as follows:

<code class="php">    <?php
    ...
    echo val;
    ?>
    <html>
    <?php echo ...?>
    </html></code>
Copy after login

The entire php file contains the flavor of html. I won’t go into details, you should understand. Except for the css file, I threw up. Deeply hurt the heart of OCD. Language can still be used in this way. Once again I felt like I had chosen the wrong path. I thought the world of code could be more organized, but it seems I was wrong.
After thinking about it, I realized that if it was developed in this way, it would be hard enough for one person to cover both the front and back ends. However, this hybrid development model does have an advantage, which is low cost and high efficiency. There are a lot of shortcomings, and expansion and later maintenance are problematic.

Positive Cases

Last year, I also took over a web project. The main requirement: display the content in the background database table. To put it bluntly, it is to imitate the web control of MySQL. But it's simple. But there are requirements: Modeling, that is, by modifying a small number of parameters in the background, you can control the number of tables displayed on the front end, and even the column names of the tables. In other words, all information about the table on the front end is provided by the back end. The front-end only needs to make display adjustments to the interface based on the back-end data.

Design ideas:

1. The style of the table and the dynamic operation of the mouse on the table are used as part of the front-end module;
2. The table name information and list information of the table are returned to json by the ajax request server, and the json can be dynamically created locally by slightly verifying the json locally. Table;
3. Data acquisition also applies to ajax acquisition. Then populate the local table;
4. All local additions, deletions and modifications to data are uploaded to the server through ajax;

The only running-in point is the ajax interface. During development, due to the slowness of the backend, some interfaces passed fake data directly to the frontend through echo.

Advantages of front-end and back-end separation

Through the development of the data interface model, the front-end and back-end are completely separated, and because this project is a model-based design, the code reuse is very high.
Moreover, if a problem occurs, by detecting the data in the data interface, it is easy to know whether it is a front-end problem or a back-end problem. It is very easy to maintain and even carry out in-depth secondary development.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template