Table of Contents
Origin
Goals
Tools
Methodology
Home Web Front-end JS Tutorial Example tutorial on separation of front-end and back-end

Example tutorial on separation of front-end and back-end

Jun 24, 2017 pm 02:39 PM
separation rear end think

Origin

As the company increases its developers and the number of projects, the cost of front-end and back-end communication continues to increase. The original project's front-end and back-end were not separated. As a front-end, you also need to have some understanding of back-end languages ​​​​such as PHP. This greatly increased the learning cost of front-end development, especially when you encounter database errors and do not understand the reason, spending a lot of time. solve. Therefore, based on our current business needs, we started to try to separate the front and back ends from some new projects.

Goals

1) Code separation. The front-end and back-end codes are separated using independent project directories. The front-end development environment does not need to configure PHP or Java environment. All project codes are managed using Git.
2) Development process improvement. The development process will be divided into local [local development], dev [front-end and back-end joint debugging], beta [QA testing] and prod [online release].

Tools

Nodejs
Webpack
Command pad
HostProfiles
Git
Sftp

Methodology

1) Determine the requirements and design the interface.
In the entire development process, after the requirements and design are determined, the front-end and back-end must first design the interface, determine the parameters of the corresponding interface and the JSON structure of the returned data, and then develop independently.
2) Local development
The local development environment can be built with the help of Grunt, Gulp, and Webpack. We usually use Webpack to achieve it, because Webpack can It supports modularization, has relatively good support for development such as React and VUE, and is relatively popular in the community. Problems can be solved relatively quickly. Using Webpack and Webpack-dev-server, you can quickly build a local service that supports hot loading and refreshing of code. Of course, you can build simple services through express.
At this time we usually use Command Pad to manage the command line, such as the commonly used npm start, or npm run dist, etc., which is convenient and fast.
Image resources are managed in a unified directory and deployed to Qiniu in advance.
Local development will use the mock data method to simulate the interface and develop the page logic. In some projects where jquery exists, we use jquery.mockjax.js as the mock tool. Usually, an api directory is created to centrally manage all interface data, and is loaded and blocked uniformly through an index.js.
3) Front-end and back-end joint debugging
After the front-end and front-end are separated, the joint debugging of front-end and back-end data will be very simple and efficient. You only need to deploy the code to DEV respectively. on the server, and then use the development tools provided by chrome to debug. If you encounter problems during the debugging process, you can modify and submit them at any time. The front-end will not rely on the back-end development environment. Even if there is a problem with the DEV environment, the back-end can handle it in a timely manner with a clear division of labor. Especially after the introduction of Docker, we can easily create multiple DEV development environments, so that even if multiple colleagues develop a project, they will not affect each other's joint debugging of DEV.
When releasing the code, Sublime Text's plug-in sftp was introduced to directly push the locally compiled code to the DEV server, making the whole process faster.
4) QA test
Entering the QA test phase, it is almost similar to the joint debugging phase, except that it provides an online-like environment, which is provided separately For testing use.
5) Online publishing
Before publishing, the code needs to be compressed and packaged, which is also done with the help of Webpack. What is worth mentioning is that when a bug occurs online, we need to map the online code to local for debugging, using HostProfiles and nginx. Use the branch function of git to create a hotfix branch for processing.
This is a simple front-end and back-end separation solution. It is just a solution proposed for the company's existing project situation. Of course, there are many places that can be improved. For example, Taobao's Midway Plan adds a middle layer of nodejs for template rendering and business processing.

The above is the detailed content of Example tutorial on separation of front-end and back-end. For more information, please follow other related articles on the PHP Chinese website!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Detailed graphic explanation of the memory and GC of the Node V8 engine Detailed graphic explanation of the memory and GC of the Node V8 engine Mar 29, 2023 pm 06:02 PM

This article will give you an in-depth understanding of the memory and garbage collector (GC) of the NodeJS V8 engine. I hope it will be helpful to you!

An article about memory control in Node An article about memory control in Node Apr 26, 2023 pm 05:37 PM

The Node service built based on non-blocking and event-driven has the advantage of low memory consumption and is very suitable for handling massive network requests. Under the premise of massive requests, issues related to "memory control" need to be considered. 1. V8’s garbage collection mechanism and memory limitations Js is controlled by the garbage collection machine

A brief analysis of the problem that the server cannot be remote after installing Pagoda A brief analysis of the problem that the server cannot be remote after installing Pagoda Nov 23, 2022 pm 04:56 PM

This article uses the Pagoda Panel Tutorial column to introduce to you the problem that server2022 cannot be remote after installing Pagoda. I wonder if you have encountered such a problem? Let me show you how I handle it!

Why is count(*) so slow? Cause Analysis Why is count(*) so slow? Cause Analysis Jan 05, 2023 pm 09:21 PM

Why is count(*) so slow? The following article will analyze the reasons for you and talk about the execution process of count(*). I hope it will be helpful to everyone!

A brief analysis of closures in Golang A brief analysis of closures in Golang Nov 21, 2022 pm 08:36 PM

A closure is a combination of a function and a reference to its bundled surrounding environment (lexical environment). In other words, closures allow developers to access the scope of an outer function from an inner function. Closures are created when the function is created.

12 points to note when sharing interface design documents 12 points to note when sharing interface design documents Apr 24, 2023 am 10:58 AM

Recently, when I was reviewing the interface document, I found that the parameter defined by a small partner was an enumeration value, but the interface document did not give the corresponding specific enumeration value. In fact, how to write interface documents well is really important. Today, Brother Tianluo brings you 12 points to pay attention to in interface design documents~

In-depth understanding of generics in golang (Generic) In-depth understanding of generics in golang (Generic) Apr 11, 2023 pm 07:20 PM

What this article brings to you is an in-depth understanding of generics in golang? How to use generics? It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

How to compress large text storage in MySQL How to compress large text storage in MySQL Feb 02, 2023 pm 08:23 PM

Conduct a simple investigation on MySQL large text data storage and compress the data at the expense of some CPU resources so that the data takes up less space, thereby reducing disk I/O and network I/O.

See all articles