Based on the separation of front and rear end terminal adapter

By Dustin Hawkins,2015-09-25 00:35
16 views 0
Based on the separation of front and rear end terminal adapter

    Based on the separation of front and rear end

    terminal adapter


    In recent years the site based on Web terminal adapter in full swing, the industry also developed relying on various technical solutions.Like a browser-based native range of Media Query response type design, "cloud adaptation scheme based on the cloud intelligent rearrangement, etc.This article mainly discusses in front end separation under the basis of many terminal adapter.

    About before and after the separation

    In about end separate solution before and afterUA detection

    For many terminal adapter is UA detection problem to solve first, for a request, we need to know the type of the device can output corresponding to the content of it.Now on the market has been very mature compatible with a large number of equipment User Agent feature library and detection tools,Here are the Mozilla finishing a list.Among them, both run in the browser, there are also running on the server code layer, and even some tool provides Nginx/Apache module, responsible for parsing UA information per request.

    In fact, we recommend a way finally.Based on the separation of front and back end project determines the UA detection can only run on the server side, but if the code detection and feature library coupling in the business code is not a friendly enough.We go on to the behavior, hung on Nginx/Apache, they are responsible for parsing UA information for each of the request, through the way such as HTTP Header is passed to the business code.

    Doing this there are several benefits:

    1. Our code without having to pay close attention to UA inside how to

    parse, and directly from the upper after parsing the information.

    2. If there are multiple applications on the same server, can use the

    same Nginx parsed UA information, save the resolution loss between

    the different applications.

    From Tmall share UA detection scheme based on Nginx

    Taobao's Tengine Web server provides a similar


    Be worth what carry is, choose UA detection tools must be considered when the maintainability of the feature library, because more and more new types of equipment on the market, each device has its own User Agent, so the feature library must provide good update and maintenance strategy, to adapt to the constantly changing equipment.

    Based on the MVC pattern of several kinds of adaptation scheme

    Obtain UA information, we will consider if the terminal adapter according to the specified UA.Even in NodeJS layer, although do not have most of the business logic, however, we still put inside is divided into the Model/Controller/View Model of the three.

    We first use of the figure above, to resolve some existing terminal adapter. Based on the Controller adaptation scheme

    This solution should be the most simple and crude processing method.By routing (Router) transfer the same URL unified to the same control layer (Controller).Control layer again by UA information data and Model (Model) distributed logic to the corresponding display (View) rendering, rendering layer is several terminal by prior agreement to provide the adaptation of the template.

    The benefits of this approach is that maintain the unity of the data and control layer, business logic can only deal with once applied on all

    terminals.But this scenario is only suitable for low interaction type applications such as display page, once the business is more complex, the terminal Controller may have their own processing logic, if still share a Controller, can cause the Controller is very heavy and difficult to maintain, this is a wrong choice.

    Based on the Router adaptation scheme

    In order to solve the above problems, we can classify the equipment on the Router, and distributed to different according to different terminal Controller: