CN107562427B - Page template engine rendering method based on NodeJS - Google Patents
Page template engine rendering method based on NodeJS Download PDFInfo
- Publication number
- CN107562427B CN107562427B CN201710801833.1A CN201710801833A CN107562427B CN 107562427 B CN107562427 B CN 107562427B CN 201710801833 A CN201710801833 A CN 201710801833A CN 107562427 B CN107562427 B CN 107562427B
- Authority
- CN
- China
- Prior art keywords
- page
- nodejs
- data
- login
- arttemplate
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
Images
Landscapes
- Information Transfer Between Computers (AREA)
Abstract
The invention relates to a page template engine rendering method based on NodeJS, which is characterized in that under a framework with separated front and back ends, by adding an intermediate layer NodeJS, corresponding business logics are realized, and simultaneously, an artTemplate engine is introduced on the basis, so that a corresponding page element can be found in an access page path at the intermediate layer, and a server end is requested to synchronously render and display data, thereby not only solving the problem that synchronous rendering cannot be realized under an SPA mode, but also well solving the problem of seo optimization.
Description
Technical Field
The invention relates to a webpage rendering method, in particular to a NodeJS-based webpage template engine rendering method under a framework with front and back ends separated.
Background
With the rise of different terminals (Pad/Mobile/PC), the requirement on developers is higher, the response type of a pure browser cannot meet the high requirement on user experience, and customized versions are often required to be developed for different terminals. In order to improve development efficiency, the requirement of front-end and back-end separation is more and more emphasized, the back end is responsible for a business/data interface, the front end is responsible for showing/interacting logic, and multiple versions can be customized and developed through the same data interface.
However, it is now agreed that a common example of front-end and back-end separation is SPA (Single-page application), and all used presentation data is provided by the back-end via asynchronous interface (AJAX/JSONP), and the front-end is only responsible for presentation.
In a sense, SPA does achieve front-to-back separation, but this approach has two problems:
1. in WEB services, the proportion of SPA classes is small, and in many scenes, a synchronous rendering mode or a synchronous and asynchronous mixed mode is provided, so that the SPA cannot be used as a general solution;
2. the Ajax is a main SPA type development mode, is suitable for developing scenes of APP types, but is only suitable for APP, because SEO and other problems are not solved well, and the development mode is too heavy for various types of systems.
The SPA cannot meet the front-end and back-end separation requirements, and the SPA is considered to be divided from responsibility to meet the use scene, so that the SPA is generated.
Disclosure of Invention
The invention aims to provide a NodeJS-based page template engine rendering method, which introduces NodeJS as a control layer under a front-end and back-end separation architecture and realizes synchronous rendering of pages through an artTemplate engine.
In order to achieve the purpose, the invention adopts the technical scheme that:
a rendering method of a page template engine based on NodeJS comprises the following steps:
step 1, a page request is transmitted to a NodeJS terminal monitoring a corresponding port through nginx configuration;
step 2, analyzing UR L, obtaining the corresponding page name and the module to which the page belongs, matching the configuration of the page by reading the page configuration file in combination with the module name, and jumping to the 404 page if the module does not exist or the page does not exist under the module;
step 3, judging whether login needs to be filtered or not under the condition that the page exists, if the page needs to be filtered and logged in, judging whether login exists or not through a control layer NodeJS request server interface, if not, redirecting to a login page, and if not, entering the next step; if the page does not need filtering login, directly entering the next step;
and 4, reading the default configuration and merging the default configuration and the data of the slave server end into json by using an artTemplate engine, binding the corresponding page and the data together through the artTemplate, and synchronously displaying the page and the data to the view layer.
The redirection and the jump (including 404, 500, login page and the like) of the page can pass through the middle layer NodeJS, the control layer logic which is previously placed in the back-end processing can be placed in the middle layer NodeJS for processing, the display of the page is not a simple static page any more, but data after business data are interacted and page synchronous rendering display can be carried out.
And 5, binding the corresponding page and the data together through the artTemplate, and synchronously displaying the page and the data to the view layer, wherein the js script is executed in the foreground to render the data to the designated area of the page through asynchronous interaction.
By adopting the scheme, the invention not only solves the problem that the synchronization or the mixing of the synchronization and the asynchronization can not be realized under the SPA mode, but also can well solve the problem of the seo optimization, and improves the security index of the website. For developers, the mode not only makes the responsibility clearer and facilitates the cooperation, but also greatly improves the development efficiency. This approach greatly improves the user experience for the user.
Drawings
FIG. 1 is a schematic diagram of a page template rendering process.
The invention is further described in detail below with reference to the figures and examples.
Detailed Description
As shown in FIG. 1, the present invention discloses a NodeJS-based page stencil engine rendering method, which comprises the following steps:
a rendering method of a page template engine based on NodeJS comprises the following steps:
step 1, a page request is transmitted to a NodeJS terminal monitoring a corresponding port through nginx configuration;
step 2, analyzing UR L, obtaining the corresponding page name and the module to which the page belongs, matching the configuration of the page by reading a page configuration file in combination with the module name, including the page name, whether filtering and logging are needed, whether synchronous rendering of a page template and data is needed, and jumping to 404 pages if the module does not exist or the page does not exist under the module;
step 3, judging whether login needs to be filtered or not under the condition that the page exists, if the page needs to be filtered and logged in, judging whether login exists or not through a control layer NodeJS request server interface, if not, redirecting to a login page, and if not, entering the next step; if the page does not need filtering login, directly entering the next step;
and 4, reading default configuration (static resource address and the like) and merging the default configuration and data of a slave server (java/php) into json by utilizing an artTemplate engine, binding the corresponding page and the data together through the artTemplate, and synchronously displaying the page and the data to a view layer, namely displaying the page and the data by a browser.
The redirection and the jump (including 404, 500, login page and the like) of the page can pass through the middle layer NodeJS, the control layer logic which is previously placed in the back-end processing can be placed in the middle layer NodeJS for processing, the display of the page is not a simple static page any more, but data after business data are interacted and page synchronous rendering display can be carried out.
A step, namely step 5, can be added on the basis of step 4 to realize synchronous and asynchronous mixed rendering of the pages.
And 5, binding the corresponding page and the data together through the artTemplate, and synchronously displaying the page and the data to the view layer, and executing js script by the foreground to render the data to a page designated area through asynchronous interaction, so that a mixed mode that the data can be synchronously displayed to a browser with the page, the user experience is increased, and asynchronous rendering can be requested through Ajax is formed.
The method is characterized in that under a framework with separated front and back ends, on the basis of NodeJS, corresponding business logics are realized, meanwhile, an artTemplate engine is utilized to read default configuration (static resource addresses and the like) and data of a slave server end (java/php) to be merged into json, a corresponding page and the data are bound together through the artTemplate and are synchronously displayed on a view layer, and synchronous rendering of the page is realized. Or on the basis of binding the corresponding page and the data together through the artTemplate and synchronously displaying the bound page and the data to the view layer, the front stage executes js script to render the data to the designated area of the page through asynchronous interaction, so that a mixed mode that the data can be synchronously displayed to the browser with the page, the user experience is increased, asynchronous rendering can be requested through Ajax, and synchronous and asynchronous mixed rendering of the page is realized.
In the conventional file stream reading mode based on NodeJS, a file reading fs.readFile () method based on NodeJS service is used for reading a webpage template file, the mode cannot realize synchronous rendering of data and a page, and some common page structures cannot be taken out, so that the workload of developers is greatly increased, one place is changed into a plurality of places by changing the frequently encountered requirements when an internet product is made, the work is complicated, the error is easy to occur, and the user experience is reduced. In the invention, by adding the intermediate layer NodeJS, the artTemplate engine is introduced on the basis of realizing some corresponding service logics, so that the access page path can be taken in the intermediate layer to find the corresponding page elements, and the data of the server is requested to be synchronously rendered and displayed, so that the realization of single sign-on is simpler and clearer, and the user experience is greatly improved.
The above description is only a preferred embodiment of the present invention, and is not intended to limit the technical scope of the present invention, so that any minor modifications, equivalent changes and modifications made to the above embodiment according to the technical spirit of the present invention are within the technical scope of the present invention.
Claims (2)
1. A rendering method of a page template engine based on NodeJS is characterized in that: the method comprises the following steps:
step 1, a page request is transmitted to a NodeJS terminal monitoring a corresponding port through nginx configuration;
step 2, analyzing UR L, obtaining the corresponding page name and the module to which the page belongs, matching the configuration of the page by reading the page configuration file in combination with the module name, and jumping to the 404 page if the module does not exist or the page does not exist under the module;
step 3, judging whether the login needs to be filtered or not under the condition that the page exists, if the page needs to be filtered and logged, judging whether the login exists or not through a control layer NodeJS request server interface, if the login does not exist, redirecting to a login page, and if the login does not exist, entering the next step; if the page does not need filtering login, directly entering the next step;
and 4, reading the default configuration and merging the default configuration and the data of the slave server end into json by using an artTemplate engine, binding the corresponding page and the data together through the artTemplate, and synchronously displaying the page and the data to the view layer.
2. The NodeJS-based page template engine rendering method as recited in claim 1, wherein: and 5, binding the corresponding page and the data together through the artTemplate, and synchronously displaying the page and the data to the view layer, wherein the js script is executed in the foreground to render the data to the designated area of the page through asynchronous interaction.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201710801833.1A CN107562427B (en) | 2017-09-07 | 2017-09-07 | Page template engine rendering method based on NodeJS |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201710801833.1A CN107562427B (en) | 2017-09-07 | 2017-09-07 | Page template engine rendering method based on NodeJS |
Publications (2)
Publication Number | Publication Date |
---|---|
CN107562427A CN107562427A (en) | 2018-01-09 |
CN107562427B true CN107562427B (en) | 2020-07-10 |
Family
ID=60979847
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201710801833.1A Active CN107562427B (en) | 2017-09-07 | 2017-09-07 | Page template engine rendering method based on NodeJS |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN107562427B (en) |
Families Citing this family (5)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US10628189B2 (en) | 2018-04-23 | 2020-04-21 | Micro Focus Llc | Synchronous operation method performance in context of asynchronous event loop |
CN109656670B (en) * | 2018-12-27 | 2020-11-20 | 广州华多网络科技有限公司 | Page rendering method and device |
CN110532491B (en) * | 2019-08-19 | 2022-05-06 | 无线生活(杭州)信息科技有限公司 | Front-end page construction method and device |
CN111381921B (en) * | 2020-03-04 | 2020-10-09 | 北京东方金信科技有限公司 | Front-end and back-end separation system and method based on Ambari |
CN115586896B (en) * | 2022-09-29 | 2023-08-04 | 通号智慧城市研究设计院有限公司 | Page project development method, equipment and storage medium based on template engine |
Family Cites Families (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN103970534A (en) * | 2014-04-15 | 2014-08-06 | 百度在线网络技术(北京)有限公司 | Method and equipment for supplying rendered page in mobile application |
CN104158836B (en) * | 2014-06-23 | 2018-05-01 | 浙江大学城市学院 | A kind of method by data render mobile application interface |
CN106302747A (en) * | 2016-08-17 | 2017-01-04 | 北京乐美无限科技有限公司 | A kind of business cloud platform of Internet WEB front-end exploitation |
-
2017
- 2017-09-07 CN CN201710801833.1A patent/CN107562427B/en active Active
Also Published As
Publication number | Publication date |
---|---|
CN107562427A (en) | 2018-01-09 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN107562427B (en) | Page template engine rendering method based on NodeJS | |
CN109597617B (en) | Method and device for quickly generating service page based on template | |
US9355081B2 (en) | Transforming HTML forms into mobile native forms | |
US7870482B2 (en) | Web browser extension for simplified utilization of web services | |
US10289278B2 (en) | Displaying webpage information of parent tab associated with new child tab on graphical user interface | |
US10284671B2 (en) | Dynamic bundling of web components for asynchronous delivery | |
CN110020329B (en) | Method, device and system for generating webpage | |
US11611633B2 (en) | Systems and methods for platform-independent application publishing to a front-end interface | |
CN103258058B (en) | Page display method and system and browser | |
JP2022553663A (en) | Content identification method, system and program for tabular data using machine learning | |
CN102662766B (en) | Microblog and social networking information synchronizing system and synchronizing method based on Web Element mechanism | |
CN107122172B (en) | Light application processing method, light application running method, light application equipment and light application equipment | |
WO2022048141A1 (en) | Image processing method and apparatus, and computer readable storage medium | |
US10795633B2 (en) | Desktop sharing method and mobile terminal | |
CN108563477B (en) | Page event response method and device | |
CN111880813B (en) | Method for realizing android card UI (user interface) and storage medium | |
CN108984070B (en) | Method, apparatus, electronic device and readable medium for thermodynamic diagram imaging | |
US10747943B2 (en) | Method, device, client apparatus, and electronic device for presenting webpages | |
CN112287255A (en) | Page construction method and device, computing equipment and computer readable storage medium | |
US10838579B2 (en) | Custom list for keyboard navigation of user interface | |
US20150378688A1 (en) | Developing rich internet application | |
US11843679B2 (en) | Automated dependency management based on page components | |
CN105138322B (en) | Generate the method and system of application program | |
CN111277889B (en) | Television side page preview method and system | |
CN113553123A (en) | Data processing method and device, electronic equipment and storage medium |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |