Page server-side rendering method and device, equipment and medium
By using a template engine based on compiled language development for static verification optimization and HTML code optimization, the problems of inefficient rendering efficiency and lack of static verification in the existing technology are solved, efficient, stable and accurate page rendering is achieved, and user experience and business benefits are improved.
Patent Information
- Application Number
- CN202510280408.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-03-10
- Publication Date
- 2025-06-27
AI Technical Summary
When faced with the high concurrent access and complex business logic of e-commerce platforms, existing page server-side rendering technology has problems such as inefficient rendering efficiency, lack of static verification mechanism, and unoptimized HTML code, resulting in reduced user experience and impact on business benefits.
Using a template engine developed based on the compilation language, an abstract syntax tree is generated by parsing the template file, static verification optimization is performed, and business data is bound to the template variables, the optimized rendering code is generated, and the redundant information is removed to generate the final page code.
It significantly accelerates the speed of page rendering, improves user experience, ensures the accuracy and stability of page rendering, reduces the risk of user churn, and improves the overall operational efficiency of the platform.
Smart Images

Figure CN120216795A_ABST
Abstract
Description
Technical Field
[0001] This application relates to page generation technology, and particularly to a method, apparatus, device, and medium for server-side rendering of pages. Background Art
[0002] In an e-commerce platform, the quick response and efficient rendering of website pages are crucial for enhancing user experience and promoting transactions. However, existing server-side page rendering technologies have the following technical problems when faced with high-concurrency access and complex business logics in an e-commerce platform:
[0003] Firstly, existing rendering technologies usually rely on template engines developed in interpreted languages, which are inefficient in processing complex template files. Especially in the high-concurrency scenario of an e-commerce platform, the template engine needs to frequently parse template files and bind business data, resulting in slow page rendering speed, increased user waiting time, and reduced user experience.
[0004] Secondly, when existing template engines process template files, they lack an effective static verification mechanism for template logic. This means that logical relationships such as variable scopes, expression priorities, and custom tags in templates can only be checked at runtime and cannot be carefully verified during the rendering stage. Once an error occurs, it often leads to page rendering failure or incorrect content. In an e-commerce platform, such errors not only affect user experience but may also result in incorrect display of transaction information and even cause security issues.
[0005] In addition, existing rendering technologies lack optimization for HTML code when generating the final page code. The generated HTML code often contains a large amount of redundant information, such as extra whitespace characters and comments, which not only increases the data volume transmitted by the page but also reduces the page loading speed. In an e-commerce platform, the delay in page loading speed may lead to user loss, thus affecting the commercial benefits of the platform.
[0006] It can be seen that existing server-side page rendering technologies have problems such as low rendering efficiency, lack of static verification mechanism, and unoptimized HTML code when faced with high-concurrency access and complex business logics in an e-commerce platform. These problems limit the user experience and commercial benefits of the e-commerce platform, and there is an urgent need for a new solution to overcome these technical bottlenecks. Summary of the Invention
[0007] The purpose of this application is to solve the above problems by providing a method for server-side rendering of pages, as well as its corresponding apparatus, device, non-volatile readable storage medium, and computer program product.
[0008] According to one aspect of this application, a method for server-side rendering of pages is provided, including:
[0009] In response to a page access request sent by a client, based on the page identifier of the page to be accessed included in the request, a template engine developed based on a compiled language is called to obtain a corresponding template file according to the page identifier;
[0010] The template engine parses the template file to generate a corresponding abstract syntax tree, and the abstract syntax tree represents the logical relationship information among the mixed operation expressions, variable scopes, custom tags, business data filters, and control statements in the template file;
[0011] Based on the abstract syntax tree, the template engine performs static verification and optimization on the logical relationship information in the template file, and binds the business data obtained from the data source to the corresponding variables in the template file according to the correspondence between the variables and the business data, to obtain optimized rendering code;
[0012] The template engine generates and removes redundant information from the rendering code to obtain the final page code, and sends the final page code to the client for rendering and display.
[0013] According to another aspect of the present application, there is provided a page server-side rendering device, including:
[0014] An engine call module, configured to respond to a page access request sent by a client, and based on the page identifier of the page to be accessed included in the request, call a template engine developed based on a compiled language to obtain a corresponding template file according to the page identifier;
[0015] A template parsing module, configured to parse the template file by the template engine to generate a corresponding abstract syntax tree, and the abstract syntax tree represents the logical relationship information among the mixed operation expressions, variable scopes, custom tags, business data filters, and control statements in the template file;
[0016] A template rendering module, configured to perform static verification and optimization on the logical relationship information in the template file by the template engine, and bind the business data obtained from the data source to the corresponding variables in the template file to obtain optimized rendering code;
[0017] A page output module, configured to generate and remove redundant information from the rendering code by the template engine to obtain the final page code, and send the final page code to the client for rendering and display.
[0018] According to another aspect of the present application, there is provided a page server-side rendering device, including a central processing unit and a memory, and the central processing unit is configured to call and run a computer program stored in the memory to execute the steps of the method described in the present application.
[0019] According to another aspect of the present application, there is provided a non-volatile readable storage medium, which stores a computer program implemented according to the page server-side rendering method described above in the form of computer-readable instructions. When the computer program is called and run by a computer, it executes the steps included in this method.
[0020] According to another aspect of the present application, there is provided a computer program product, including a computer program / instructions, and when the computer program / instructions are executed by a processor, the steps of the method are implemented.
[0021] The template engine developed based on a compiled language in the present application comprehensively optimizes the rendering process of template files, can serve page rendering scenarios including websites, emails, etc., and can achieve significant beneficial technical effects. First, by leveraging the high efficiency of the compiled language, the template engine can quickly parse template files and bind business data, significantly accelerating the page rendering speed, reducing the user waiting time, enhancing the user experience, and at the same time enhancing the stability and reliability of the platform under high-traffic access. This technical advantage is more prominent when applied in high-concurrency scenarios of e-commerce platforms. Second, by constructing an abstract syntax tree and performing static verification optimization, the template engine can detect and correct logical errors in the template in advance during the rendering stage, such as errors in variable scopes, mixed operation expressions, custom tags, etc., avoiding runtime errors, ensuring the accuracy and stability of page rendering, effectively preventing incorrect display of transaction information, guaranteeing transaction security, and reducing the risk of user loss. In addition, when generating the final page code, the template engine can clean up redundant information, remove unnecessary whitespace characters and comments, make the generated HTML code more concise and efficient, reduce the amount of transmitted data, accelerate the page loading speed, reduce the server bandwidth consumption, and improve the overall operation efficiency of the platform. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] Figure 1 This is an exemplary network architecture of the present application, and the server therein can be used to deploy and run a computer program product implemented according to the page server-side rendering method of the present application for rendering website pages.
[0023] Figure 2 This is a schematic flowchart of an embodiment of the page server-side rendering method of the present application.
[0024] Figure 3 This is a principle block diagram of the page server-side rendering device of the present application.
[0025] Figure 4 This is a schematic structural diagram of a page server-side rendering device adopted by the present application. DETAILED DESCRIPTION OF THE EMBODIMENTS
[0026] Such as Figure 1As shown, the network architecture of the present application mainly includes a front-end server 81 and a terminal device 80 as a client. In an exemplary application scenario of the present application, the front-end server 81 serves as the core server cluster of an e-commerce platform and runs a computer program product implemented according to the page server-side rendering method of the present application. By running the corresponding computer program, it undertakes the function of calling a template engine to render a template file in response to a request from the client 80, obtaining the final page code of the requested page and returning it to the client.
[0027] The template engine of the present application is suitable for rendering various pages, including but not limited to website pages, email layout pages, pages embedded in applications in terminal devices, etc. The common feature of such pages is that they have the form of final page code described in HTML language.
[0028] For example, in the actual operation of an e-commerce platform, especially in high-concurrency scenarios such as product rush purchases, it is crucial to quickly respond to client requests and efficiently render pages. For example, in an exemplary product rush purchase scenario, a user sends a page access request to the front-end server through a terminal device (such as a computer, mobile phone, etc.). After receiving the request, the front-end server calls the template engine to obtain the corresponding template file according to the page identifier included in the request. The template engine parses the template file to generate an abstract syntax tree, which can clearly represent the logical relationship information between the mixed operation expressions, variable scopes, custom tags, business data filters, and control statements in the template file. Based on this, the template engine can perform static verification and optimization on the logical relationship in the template file, bind the business data obtained from the data source to the corresponding variables in the template file, finally generate optimized rendering code, and then generate the final page code of the website page and return it to the client for rendering and display.
[0029] In the present application, the template engine is a key component to implement the above process. It is developed based on a compiled language and has higher execution efficiency and stronger business processing capabilities compared with traditional interpreted template engines. In the present application, the template engine can not only quickly parse the template file, but also construct an abstract syntax tree during the parsing stage to achieve static verification and optimization of the template logic, discover and correct potential errors in advance, and ensure the accuracy and stability of page rendering. In addition, when generating the final page code, the template engine can clean up redundant information, remove unnecessary whitespace characters and comments, make the generated HTML code more concise and efficient, reduce the page transmission data volume, speed up the page loading speed, and thus improve the user experience.
[0030] Please refer to Figure 2 , in some embodiments of the page server-side rendering method of the present application, it includes the following steps:
[0031] Step S3100: In response to a page access request sent by a client, based on the page identifier included in the request, call a template engine developed based on a compiled language to obtain a corresponding template file according to the page identifier;
[0032] Taking the e-commerce platform application scenario as an example, when a user accesses an e-commerce platform through a terminal device (such as a computer, mobile phone, etc.), the client will send a page access request containing a page identifier to the server to obtain the final page code of the corresponding page. Taking a promotional email as an example, when a recipient opens an email, the terminal device will similarly initiate a page access request containing a page identifier to obtain the final page code of the page required to be displayed in the email body. This page identifier is used to uniquely determine the specific page content requested by the user. For example, it may be a product details page, a shopping cart page, or a settlement page, etc. After receiving the request, the server will obtain the corresponding template file according to the page identifier, and then call a template engine developed based on a compiled language to perform server-side rendering on the template file to generate the corresponding page.
[0033] The template engine of the present application can be developed and implemented based on a compiled language such as Golang. Compared with traditional interpreted template engines, the template engine implemented based on a compiled language has higher execution efficiency and stronger business processing capabilities. The compiled language compiles the code into machine code before execution, so it can be executed faster at runtime, which enables the template engine to significantly improve efficiency when processing complex template files. In the high-concurrency scenario of an e-commerce platform, such an efficient template engine can quickly respond to client requests, thereby enhancing the user experience.
[0034] A template file is a pre-defined page structure and content template, which contains information such as the layout, style of the page, and data placeholders that need to be dynamically inserted. For example, a template file for a product details page may contain the display position of the product image, placeholders for the product name and price, etc. Template files are usually stored in a specific format, such as HTML template files embedded with syntax supported by the template engine.
[0035] Step S3200: Have the template engine parse the template file to generate a corresponding abstract syntax tree, and the abstract syntax tree represents the logical relationship information among the mixed operation expressions, variable scopes, custom tags, business data filters, and control statements in the template file;
[0036] After receiving the page access request sent by the client and obtaining the corresponding template file, the template engine will parse the template file to generate the corresponding Abstract Syntax Tree (AST). The Abstract Syntax Tree is a tree-like data structure used to represent the syntax structure of source code, which can clearly express various logical relationship information in the template file, including mixed operation expressions, variable scopes, custom tags, business data filters, and control statements, etc.
[0037] The mixed operation expressions in the template file refer to the complex expressions contained in the template, and these expressions can include logical operations, comparison operations, and arithmetic operations, etc. For example, in a product recommendation template, it may be necessary to calculate the priority of recommended products based on the user's browsing history and purchase behavior, which requires the use of mixed operation expressions to achieve. When the template engine parses the template file, it will identify these mixed operation expressions and represent them in the form of nodes in the abstract syntax tree, while recording the relationship between each operator and operand in the expression for subsequent priority parsing and syntax verification.
[0038] The variable scope refers to the range within which a variable is valid in the template file. In the template file, variables may be defined and used in different scopes, such as local variables, global variables, etc. When the template engine parses the template file, it will determine the variable scope based on the definition location and usage location of the variable, and add scope information to each variable node in the abstract syntax tree. In this way, during the subsequent data binding phase, the template engine can accurately search for and bind variables according to the scope information, avoiding variable conflicts and undefined errors.
[0039] Custom tags are a special syntax in the template file, in the form of {{#tag... / }} or {{#tag}}{{ / tag}}, which allows developers to define their own tags to implement specific functions, including but not limited to logical control (such as if, for, switch, etc.) and UI display (such as carousel function). For example, a {{#carousel / }} tag can be defined to implement the carousel function, or a {{#pagination / }} tag can be defined to implement the pagination function. When the template engine parses the template file, it will identify these custom tags and represent them in the form of nodes in the abstract syntax tree. At the same time, the template engine will record information such as the name, attributes, and content of the custom tags for subsequent semantic verification and rendering.
[0040] The business data filter is a component in the template file used to process business data. It can perform operations such as formatting, converting, or validating business data to ensure that the data meets the requirements of the template. For example, in a product list template, it may be necessary to format the product price to display it in a currency format with two decimal places. When the template engine parses the template file, it will recognize the calls to the business data filter and represent them as nodes in the abstract syntax tree. At the same time, the template engine will record information such as the name and parameters of the filter for subsequent calls to process the business data.
[0041] Control statements are syntactic structures in the template file used to control the template rendering process, such as conditional statements like if, loop statements like for, and selection statements like switch. These syntactic structures can be implemented in the form of custom tags. When the template engine parses the template file, for control statements represented by custom tags, it will also recognize them according to the syntax of the control statements and represent them as nodes in the abstract syntax tree. At the same time, the template engine will record information such as the syntax and logical structure of the control statements for subsequent verification and rendering. For example, in a product list template, it may be necessary to use a loop statement to iterate through the product data and generate a product list, and at the same time use a conditional statement to determine whether to display the promotional information of a certain product.
[0042] Step S3300: Based on the abstract syntax tree, the template engine performs static verification and optimization on the logical relationship information in the template file, and binds the business data obtained from the data source to the corresponding variables in the template file according to the correspondence between the variables and the business data, obtaining optimized rendering code;
[0043] After completing the parsing of the template file and generating the abstract syntax tree (AST), the template engine will perform static verification and optimization on the logical relationship information in the template file based on the AST, and bind the business data obtained from the data source to the corresponding variables in the template file, finally obtaining optimized rendering code.
[0044] When parsing a template file, the template engine can perform precedence parsing and syntax verification on mixed operation expressions, covering logical, comparison, and arithmetic operators. By analyzing the expression nodes in the abstract syntax tree (AST), the template engine determines the operator precedence and verifies the correctness of the expression syntax. In addition, based on the variable scope chain established in the AST, the template engine can verify whether the definition and call of variables conform to their scope rules to ensure the correct use of local and global variables. The template engine can also perform semantic verification on custom tags to verify whether their attributes and content conform to predefined rules. For example, it checks whether the items attribute of the {{#carousel / }} tag exists and has the correct format. At the same time, the template engine can verify the call interface of business data filters to ensure that the use of filters conforms to predefined rules, such as verifying whether the call of the currency filter is correct. Finally, the template engine can also verify the syntax and logical structure of control statements (such as if, for, switch) to ensure that their syntax is correct and the logic is reasonable. For example, it verifies the syntax of the for loop and the logical condition of the if statement. After completing the above static verification and optimization, the template engine binds the business data obtained from the data source to the corresponding variables in the template file. The data source can be a database, API, cache, etc., providing the business data required for page rendering. The template engine binds the data to the variables in the template according to the correspondence between the variables and the business data. For example, the itemName variable in the product details page template will be bound to the name data of the corresponding product in the database.
[0045] Through static verification optimization and data binding operations, the template engine generates optimized rendering code, preparing for the next step of generating the final page code. Accordingly, it not only improves the efficiency of page rendering but also ensures the accuracy and stability of the rendering result.
[0046] Step S3400: The template engine generates and removes redundant information from the rendering code to obtain the final page code, and sends the final page code to the client for rendering and display.
[0047] After completing the parsing of the template file, generating the abstract syntax tree (AST), and static verification optimization and data binding based on the AST, the template engine enters the page code generation stage. The goal is to convert the optimized rendering code into the final HTML page code and send it to the client for rendering and display.
[0048] Specifically, the template engine first generates the HTML code of the page based on the optimized rendering code. This process requires replacing placeholders such as variables in the template file with actual business data while retaining the HTML structure and style defined in the template file. For example, if the template file contains a placeholder for a product list, the template engine will replace the product data obtained from the data source with the placeholder position one by one to generate a complete HTML list code.
[0049] The template engine also optimizes the HTML code, removing blank characters and comments that constitute redundant information. In the template file, developers may add comments to explain the function or structure of the code, but in the final HTML code, these comments are unnecessary and will increase the amount of data transmitted for the page. By removing this redundant information, the template engine can generate more concise and efficient HTML code and speed up the loading of the page. For example, the template engine will replace consecutive blank characters with a single space and remove comment lines in the HTML code, thereby reducing the size of the HTML file.
[0050] Finally, the template engine sends the optimized HTML code as the final page code to the client for rendering and display. After the client receives the HTML code, the browser will parse and render the code and display the page content to the user. This not only improves the page loading speed, but also improves the page display effect and user experience by optimizing the HTML code structure and content.
[0051] Through the above embodiments, the template engine developed by the present application based on the compiled language comprehensively optimizes the template file rendering process and achieves a wealth of beneficial technical effects, including but not limited to:
[0052] First of all, this application effectively improves the efficiency of page server rendering by adopting a template engine developed based on a compiled language. Compiled languages have significant advantages in execution efficiency compared to traditional interpreted languages. In high-concurrency scenarios, this efficient template engine can quickly parse template files and bind business data, thereby significantly speeding up page rendering, reducing user waiting time, and thus improving user experience. This efficient rendering mechanism enables e-commerce platforms to maintain smooth page loading during high-traffic access, enhancing the stability and reliability of the platform.
[0053] Secondly, the present application introduces a static verification optimization mechanism for the logical relationship information of the template file. By constructing an abstract syntax tree during the template parsing stage and verifying the logical relationships such as variable scopes, mixed operation expressions, custom tags, business data filters, and control statements in the template based on this tree, potential errors can be detected and corrected in advance during the rendering stage. This static verification mechanism avoids the occurrence of errors caused by runtime verification in traditional technologies, ensuring the accuracy and stability of page rendering. In an e-commerce platform, this mechanism can effectively prevent the incorrect display of transaction information, ensuring the security and accuracy of transactions, and at the same time reducing the risk of user loss caused by errors.
[0054] In addition, the template engine of the present application is developed based on a compiled language and has high business capabilities. When generating the final page code according to the rendering code, it can clean up redundant information, remove unnecessary whitespace characters and comments, making the generated HTML code more concise and efficient, reducing the page transmission data volume, and accelerating the page loading speed. In an e-commerce platform, this optimization not only improves the page response speed but also reduces the bandwidth consumption of the server, enhancing the overall operation efficiency of the platform.
[0055] Based on any embodiment of the method of the present application, static verification optimization is performed on the logical relationship information in the template file, including any one or more of the following:
[0056] Step S3301: Perform priority parsing and syntax verification on the mixed operation expressions in the template file to determine that the mixed operation expressions conform to the operation rules;
[0057] After completing the parsing of the template file and generating the abstract syntax tree (AST), the template engine enters the static verification optimization stage. One of the optional key operations is to perform priority parsing and syntax verification on the mixed operation expressions in the template file to ensure that the expressions in the template can be correctly executed during the rendering stage, avoiding page rendering failures or abnormal displays caused by syntax errors or logical problems.
[0058] As revealed previously, a mixed operation expression refers to a complex expression contained in the template, which may involve logical operations, comparison operations, and arithmetic operations, etc. For example, in a product recommendation template, it may be necessary to calculate the priority of recommended products based on the user's browsing history and purchase behavior, which requires the use of mixed operation expressions to achieve. When parsing the template file, the template engine will identify these mixed operation expressions and represent them as nodes in the abstract syntax tree, while recording the relationships between each operator and operand in the expression for subsequent priority parsing and syntax verification.
[0059] Specifically, the template engine analyzes the expression nodes in the AST, determines the precedence of operators, and checks whether the syntax of the expression is correct. For example, for the expression if(user.bought(item)&&item.rating>4), the template engine will parse this expression to ensure that the use of the logical operator && and the comparison operator > conforms to the syntax rules, and the calls to the operands user.bought(item) and item.rating are valid. In this way, the template engine can detect and correct potential syntax errors in advance to ensure that the expression can be executed correctly at runtime.
[0060] In addition, the template engine also performs semantic verification on variables and function calls in the expression. For example, the template engine checks whether the variables user and item have been defined in the template file and whether their scopes are correct. At the same time, the template engine verifies whether the functions bought and rating exist and whether the parameters meet the expectations. This semantic verification can further ensure the correctness and reliability of the expression.
[0061] In practical applications, mixed operation expressions may have various specific forms. For example, in a product details page template, it may be necessary to display different information based on the stock quantity of the product and the user's purchase permission. The template engine will parse expressions like if(item.stock>0&&user.has_permission) to ensure that its logic is correct and conforms to the syntax rules. In another scenario, the template engine may process expressions involving arithmetic operations, such as total_price=item.price*item.quantity, to ensure that the use of the multiplication operator * is correct and the values of the variables item.price and item.quantity are valid numeric types.
[0062] Through the above precedence parsing and syntax checking operations, the template engine can ensure that the mixed operation expressions in the template file can be executed correctly during the rendering phase. This static verification mechanism not only improves the efficiency of page rendering but also ensures the accuracy and stability of the rendering result, providing an efficient and reliable page rendering solution for e-commerce platforms. This process is an important part of the static verification optimization of the template engine, ensuring that the logical relationship information in the template file is fully verified and optimized before rendering.
[0063] Step S3302: Based on the scope chain of variables established during the template file parsing phase and represented in the abstract syntax tree, verify that the definition and call of variables conform to their scope rules;
[0064] In the template file parsing stage described above, the template engine established a scope chain for variables based on the Abstract Syntax Tree (AST). This scope chain is used to ensure that the definition and invocation of variables in the template file comply with their scope rules. Specifically, through the scope chain, the template engine can clearly define the scope of each variable, so as to accurately find and bind variables during the data binding stage, avoiding variable conflicts and undefined errors.
[0065] The process of establishing the variable scope chain is as follows: When parsing the template file, the template engine determines the scope of variables according to the definition location and usage location of variables. For example, in a template file, local variables are only valid within a specific code block, while global variables can be accessed throughout the template file. The template engine adds scope information to each variable node and constructs a hierarchical structure in the AST, namely the scope chain. In this way, the template engine can quickly locate the definition location of variables according to the scope chain during the subsequent data binding stage to ensure the correct use of variables.
[0066] In the static verification and optimization stage, the template engine uses the scope chain to verify the definition and invocation of variables. For example, in a product details page template, the local variable itemPrice may only be valid in the part where the product price is displayed. The template engine will ensure through the scope chain that this variable is not misreferenced outside this part. This verification mechanism can detect variable usage errors in advance, avoid runtime errors, and ensure the accuracy and stability of page rendering.
[0067] In addition, based on the scope chain, the template engine can also implement more complex verification logics. For example, the template engine can detect whether a variable is redefined or used without being defined. These verification logics can be implemented by traversing the scope chain to ensure that the variable usage in the template file complies with predefined rules.
[0068] It can be seen that by establishing and using the variable scope chain, the template engine can effectively perform static verification and optimization to ensure that the definition and invocation of variables in the template file comply with their scope rules. This mechanism not only improves the maintainability and readability of the template file, but also enhances the accuracy and stability of page rendering by detecting potential errors in advance, providing an efficient and reliable page rendering solution for the e-commerce platform.
[0069] Step S3303: Perform semantic verification on the custom tags to determine whether the custom tags comply with the custom rules;
[0070] The template engine can perform semantic verification on the custom tags in the template file to ensure that the use of custom tags complies with the predefined rules, thereby ensuring the correctness of the template file and the stability of the rendering result.
[0071] As revealed previously, custom tags are a special syntax in template files, in the form of {{#tag... / }}{{#tag}}{{ / tag}}, which allows developers to define their own tags to achieve specific functions. For example, a {{#carousel / }} tag can be defined to implement a carousel function, or a {{#pagination / }} tag can be defined to implement a pagination function. These custom tags usually have specific attributes and content structures, and the template engine needs to ensure that the use of these tags complies with predefined rules.
[0072] During the template file parsing phase, the template engine will identify all custom tags and represent them as nodes in the Abstract Syntax Tree (AST). At the same time, the template engine will record information such as the name, attributes, and content of each custom tag. For example, the template file may contain a {{#carousel / }} tag for implementing a carousel function. The template engine will parse this tag and create a corresponding node in the AST, recording its name carousel, attributes items and autoplay, and the content of its sub-tag {{#item / }}.
[0073] During the semantic verification phase, the template engine will check whether the use of custom tags complies with predefined rules. These rules usually include whether the attributes of the tag are complete, whether the format of the attribute values is correct, and whether the structure of the sub-tags meets the expectations. For example, for the {{#carousel / }} tag, the template engine will check the following points:
[0074] 1. Attribute completeness: The template engine will check whether the {{#carousel / }} tag contains the required attribute items, which is used to specify the list of items in the carousel. If this attribute is missing, the template engine will report an error, prompting the developer to correct the template file.
[0075] 2. Attribute value format: The template engine will check whether the value of the items attribute conforms to the expected format. For example, the value of the items attribute should be a variable that is defined in the template file and points to an array containing carousel item data. If the value of the items attribute does not conform to the expected format, the template engine will report an error and prompt the developer to correct it.
[0076] 3. Sub-tag structure: The template engine will check whether the sub-tag {{#item / }} of the {{#carousel / }} tag conforms to the expected structure. For example, the {{#item / }} tag should contain a tag for displaying the images in the carousel. If the For tags, the template engine will report an error and prompt the developer to correct it.
[0077] 4. Logical structure verification: For logical control syntax (such as if, for, switch), the template engine checks whether its syntax and logical structure conform to predefined language rules. For example, whether the conditional expression of the if statement is a valid boolean expression, whether the iteration condition of the for loop is clear and legal, and whether the branch structure of the switch statement is correct.
[0078] Through these semantic verifications, the template engine can ensure that the use of custom tags conforms to predefined rules, thus avoiding runtime errors and ensuring the accuracy and stability of page rendering. This verification mechanism not only improves the maintainability and readability of template files, but also enhances the accuracy and stability of page rendering by detecting potential errors in advance, providing an efficient and reliable page rendering solution for e-commerce platforms.
[0079] In addition, the template engine can implement more complex verification logics during the semantic verification phase. For example, the template engine can detect whether custom tags are correctly nested or whether certain attributes are used in inappropriate positions. These verification logics can be implemented by traversing the abstract syntax tree to ensure that the use of custom tags in the template file conforms to predefined rules.
[0080] Thus, by identifying custom tags and performing semantic verifications, the template engine can effectively perform static verification optimization to ensure that the definition and use of custom tags in the template file conform to its semantic rules. This mechanism not only improves the maintainability and readability of template files, but also enhances the accuracy and stability of page rendering by detecting potential errors in advance, providing an efficient and reliable page rendering solution for e-commerce platforms.
[0081] Step S3304, verify the call interface of the business data filter to determine that the call interface of the filter conforms to custom rules, where the business data filter is used to process business data for binding to corresponding variables;
[0082] The template engine can also verify the call interface of the business data filter to ensure that the use of the business data filter conforms to predefined rules, thus guaranteeing the correctness of the template file and the stability of the rendering result.
[0083] A business data filter is a component in a template file used to process business data. It can perform operations such as formatting, converting, or validating data to ensure that the data meets the requirements of the template. For example, a currency filter can be defined to format a number as a currency format, or a truncate filter can be defined to truncate long text. The template engine needs to ensure that the call interfaces of these filters comply with predefined rules to avoid runtime errors.
[0084] During the template file parsing phase, the template engine will identify all business data filter calls and represent them as nodes in the abstract syntax tree (AST). At the same time, the template engine will record information such as the name, parameters, and call location of each filter. For example, the template file may contain the following filter calls:
[0085]
[0086] In this example, currency and truncate are business data filters, which are used to format the product price as a currency format and truncate the product description respectively. The template engine will parse these filter calls and create corresponding nodes in the AST, recording their names, parameters, and call locations.
[0087] During the call interface verification phase, the template engine will check whether the use of business data filters complies with predefined rules. These rules usually include whether the filter exists, whether the number and type of parameters are correct, and whether the call location is reasonable. For example:
[0088] 1. Filter existence verification: The template engine will check whether the called filter has been defined. For example, if the currency filter is called in the template, the template engine will verify whether the filter is registered in the system. If it is not defined, an error will be reported during the static verification phase to avoid runtime errors.
[0089] 2. Parameter verification: The template engine will check whether the number and type of parameters of the filter conform to the predefined rules. For example, the truncate filter may require an integer parameter to specify the truncation length. The template engine will verify whether the correct parameter type and number are provided during the call. If the parameters do not conform to the rules, the template engine will report an error during the static verification phase.
[0090] 3. Call location verification: The template engine will check whether the call location of the filter is reasonable. For example, some filters may only be used in specific contexts. The template engine will verify whether the call location conforms to the predefined rules. If the call location is unreasonable, the template engine will report an error during the static verification phase.
[0091] Through the above verification mechanism, the template engine can ensure that the use of business data filters complies with predefined rules, thus avoiding runtime errors during the template rendering phase and improving the maintainability and readability of template files. This static verification mechanism not only improves the correctness of template files but also enhances the accuracy and stability of page rendering by detecting potential errors in advance, providing an efficient and reliable page rendering solution for e-commerce platforms.
[0092] Step S3305: Verify the syntax and logical structure of control statements to determine that the expressions of control statements conform to predefined language rules.
[0093] The template engine can also verify the control statements in the template file. By verification, it ensures that the syntax and logical structure of control statements conform to predefined language rules, thus guaranteeing the correctness of template files and the stability of rendering results.
[0094] Control statements are syntactic structures in template files used to control the template rendering process, such as conditional statements (if, else), loop statements (for, while), and selection statements (switch, case), etc. The correct use of these control statements is crucial for the logical execution of templates. When the template engine parses a template file, it identifies these control statements and represents them as nodes in the abstract syntax tree (AST), while recording information such as the syntax and logical structure of control statements.
[0095] During the template file parsing phase, the template engine identifies all control statements and creates corresponding nodes in the AST. For example, the template file may contain the following control statements:
[0096]
[0097]
[0098] In this example, {{#if item.price>100}} is a conditional statement. The template engine parses this statement and creates a corresponding node in the AST, recording its conditional expression item.price>100 and the corresponding branch content.
[0099] During the semantic verification phase, the template engine checks whether the syntax of control statements is correct and the logic is reasonable. These verification rules usually include:
[0100] 1. Conditional statement verification:
[0101] o The template engine checks whether the conditional expressions of conditional statements conform to syntax rules. For example, the conditional expression of an if statement must be a valid boolean expression.
[0102] o The template engine also checks whether the if statement contains a legal branch structure, such as whether there are else or elif branches, and ensures that the syntax of these branches is correct.
[0103] 2. Loop statement verification:
[0104] o The template engine checks whether the iteration condition of the loop statement conforms to the syntax rules. For example, the iteration variable and iteration range of a for loop must be clear and legal.
[0105] o The template engine also checks whether the content within the loop body is logical, such as whether there are legal variable references and expressions.
[0106] 3. Selection statement verification:
[0107] o The template engine checks whether the syntax of the selection statement (such as switch, case) is correct. For example, a switch statement must contain a valid expression, and the case branches must contain legal values.
[0108] o The template engine also checks whether the case branches are correctly nested within the switch statement and ensures that the syntax and logical structure of each case branch conform to the rules.
[0109] For example, the template file may contain the following selection statement:
[0110]
[0111]
[0112] In this example, the template engine parses the {{#switch item.type}} selection statement and creates a corresponding node in the AST, recording its expression item.type and the content of each case branch. The template engine checks whether each case branch is correctly nested within the switch statement and ensures that the value of each case branch is legal.
[0113] Through the above verification mechanism, the template engine can ensure that the syntax and logical structure of the control statements conform to the predefined language rules, thereby discovering potential errors in advance, avoiding runtime errors, and ensuring the accuracy and stability of page rendering. This static verification mechanism not only improves the maintainability and readability of the template file but also enhances the accuracy and stability of page rendering by discovering potential errors in advance, providing an efficient and reliable page rendering solution for the e-commerce platform.
[0114] Based on any embodiment of the method of the present application, binding the business data obtained from the data source to the corresponding variables in the template file includes:
[0115] Step S3311: Obtain business data related to the page to be accessed from the data source according to the correspondence between variables and business data;
[0116] Before binding business data to the corresponding variables in the template file, the template engine first obtains business data related to the page to be accessed from the data source based on the correspondence between variables and business data, ensuring that the template engine can obtain the correct data to complete page rendering.
[0117] Specifically, multiple variables are defined in the template file, and these variables need to obtain corresponding values from the data source in the backend service. The data source can be a database, an API interface, a caching system, or any other form of storage system, which provides the business data required for page rendering. The template engine parses the template file, identifies the name and type of each variable, and queries the corresponding data from the data source according to this information.
[0118] For example, assume that the template file contains a variable itemPrice for displaying the price of a product. When parsing the template file, the template engine will identify the itemPrice variable and obtain the value corresponding to this variable from the data source according to the predefined mapping relationship. If the data source is a database, the template engine may execute an SQL query statement to obtain the product price; if the data source is an API interface, the template engine may send an HTTP request to obtain the data.
[0119] In practical applications, the correspondence between variables and business data can be defined in various ways. A common way is to explicitly declare the data source path or API interface address of the variable in the template file. For example, the template file may contain the following declaration:
[0120] {{#setitemPrice=" / api / items / 123 / price" / }}
[0121] Here, the data source path of the itemPrice variable is defined as / api / items / 123 / price, and the template engine will obtain data from the API interface according to this path.
[0122] Another way is to define the relationship between variables and data sources through mapping rules in configuration files or code. For example, the configuration file may contain the following mapping rules:
[0123]
[0124] When parsing the template file, the template engine will obtain the corresponding data from the data source according to these mapping rules.
[0125] In addition, the template engine can also support the generation of dynamic data source paths. For example, it can dynamically construct data source paths based on user input or context information. Suppose there is a variable userId in the template file to identify the current user. The template engine can dynamically generate a data source path based on userId to obtain data related to the current user.
[0126] Step S3312: Invoke the business data filter to process the business data. The business data filter is used to format, transform, or validate business data.
[0127] After obtaining the business data related to the page to be accessed, the template engine will invoke the business data filter to process this data. The business data filter can be used to format, transform, or validate business data to ensure that the data conforms to the expected format and logic before being bound to template variables.
[0128] The main role of the business data filter is to preprocess the raw data obtained from the data source so that it can better adapt to the variable requirements in the template file. Such preprocessing includes, but is not limited to, data formatting, data type conversion, data validation, etc. Through these operations, the template engine can ensure that the data bound to the template variables is accurate and available, thereby improving the stability and reliability of page rendering.
[0129] The business data filter can format the data to meet the display requirements of the variables in the template file. For example, for product price data, the filter can format it into a currency format. For example, suppose there is a variable itemPrice in the template file to display the product price. The price data obtained by the template engine from the data source is 1234.56, but the template file requires it to be displayed in currency format. At this time, the business data filter will invoke a filter named currency to format the price data into $1,234.56.
[0130] The filter can also perform type conversion on the data to ensure that the data type is consistent with the requirements of the template variables. For example, if the variable in the template file requires an integer type of data, but the data source returns a string type, the filter can convert the string to an integer. For example, convert the string "123" to the integer 123.
[0131] The business data filter can also validate the data to ensure its integrity and correctness. For example, for form data entered by users, the filter can verify whether the data conforms to the expected format and range. If the data does not meet the requirements, the filter can throw an error or return a default value to avoid binding incorrect data to the template variables.
[0132] The business data filter not only supports static data processing rules but also can dynamically adjust the processing logic according to context information. For example, assume that the template file contains a variable userId to identify the current user. The template engine can dynamically generate the data source path based on userId and obtain data related to the current user from the API interface. Meanwhile, the filter can further process the data according to the user's role or permissions. For example, for an administrator user, the filter can provide more data fields, while for an ordinary user, the filter can hide some sensitive information.
[0133] The invocation rules of the business data filter can be defined through configuration files or mapping rules in the code. When parsing the template file, the template engine will obtain the corresponding data from the data source according to these mapping rules and call the specified filter for processing.
[0134] Step S3313: Bind the data processed by the business data filter to the corresponding variables in the template file to generate variable values available for rendering.
[0135] After completing the acquisition and filtering of business data, the template engine enters the crucial data binding stage. The goal of this stage is to accurately bind the data processed by the business data filter to the corresponding variables in the template file, thereby generating variable values available for rendering and providing accurate data support for subsequent page rendering.
[0136] In the steps described above, the template engine has obtained relevant business data from the data source according to the correspondence between variables and business data and has formatted, transformed, or verified this data through the business data filter. This processed data now needs to be bound to the variables defined in the template file. For example, assume that the template file defines a variable itemPrice to display the price of a product. After the template engine obtains and processes the price data corresponding to this variable, it will bind the formatted price (such as $1,234.56) to the itemPrice variable.
[0137] When binding data, the template engine will ensure the accuracy of data binding based on the variable definitions and scope information in the template file. If there are multiple variables in the template file, the template engine will bind the processed data to the corresponding variables one by one. For example, in addition to itemPrice, the template file may also define variables such as itemName and itemDescription, and the template engine will bind the corresponding name and description data to these variables respectively.
[0138] Through the implementation of the above embodiments, the present application has achieved significant technical advantages. First, by obtaining business data related to the page to be accessed from the data source and binding it based on the correspondence between variables and business data, it is ensured that the template engine can obtain accurate and relevant data to complete page rendering. This process not only improves the efficiency of data acquisition but also enhances the maintainability and readability of the template file through clear mapping relationships. Second, the business data filter is called to process the obtained business data, further ensuring that the data conforms to the expected format and logic before being bound to the template variables. This preprocessing mechanism, including data formatting, type conversion, and validation, not only improves the stability and reliability of page rendering but also enhances the security and consistency of the data. Finally, the processed data is bound to the corresponding variables in the template file to generate variable values for rendering. This process ensures that the template engine can quickly and accurately generate the final page code during the rendering stage, significantly improving the page rendering speed and user experience. It can be seen that the implementation of the above steps not only improves the efficiency and accuracy of data processing but also provides an efficient, stable, and secure page rendering solution for the e-commerce platform by optimizing the data binding and preprocessing mechanisms.
[0139] Based on any embodiment of the method of the present application, the template engine generates and removes redundant information from the rendering code to obtain the final page code, and sends the final page code to the client for rendering and display, including:
[0140] Step S3410: Generate the HTML code of the page to be accessed according to the optimized rendering code;
[0141] The template engine generates the HTML code of the page to be accessed according to the optimized rendering code. The rendering code is the result obtained by the template engine through parsing the template file, binding business data, and performing static verification and optimization in the previous steps. At this stage, the template engine converts the rendering code into specific HTML code, which includes replacing the variables in the template with actual business data and generating corresponding HTML tags and content according to the logical structure in the template file. For example, if the template file contains a loop structure for a product list, the template engine will generate the complete HTML list code according to the business data.
[0142] Step S3420: Optimize the HTML code to remove the whitespace characters and comments that constitute redundant information;
[0143] The template engine optimizes the HTML code, removing whitespace characters and comments that constitute redundant information. In the template file, developers may add comments to explain the function or structure of the code, but in the final HTML code, these comments are unnecessary and increase the page's transmission data volume. By removing this redundant information, the template engine can generate more concise and efficient HTML code, accelerating the page loading speed. For example, the template engine replaces consecutive whitespace characters with a single space and removes comment lines from the HTML code, thus reducing the size of the HTML file.
[0144] Step S3430: Send the optimized HTML code as the final page code to the client for rendering and display.
[0145] The template engine sends the optimized HTML code as the final page code to the client for rendering and display. After receiving the HTML code, the browser on the client side parses and renders the code, presenting the page content to the user. This process not only improves the page loading speed but also enhances the page display effect and user experience by optimizing the HTML code structure and content.
[0146] Through the above steps, when generating the final page code, the template engine of this application optimizes the page transmission efficiency by removing redundant information. This efficient and standardized page code generation mechanism provides the e-commerce platform with the ability to quickly respond to client requests and efficiently render pages, thereby maintaining a smooth user experience in high-concurrency access scenarios and enhancing the stability and reliability of the platform.
[0147] Based on any embodiment of the method of this application, before the template engine generates and removes redundant information from the rendering code to obtain the final page code, it further includes:
[0148] Step S2100: Perform a security check on the rendering code to detect whether there are target security vulnerabilities;
[0149] The template engine performs a security check on the rendering code to detect whether there are target security vulnerabilities. This process can identify possible security issues through static analysis of the rendering code, such as cross-site scripting (XSS), cross-site request forgery (CSRF), or other common security vulnerabilities. For example, the template engine can check whether there is unfiltered user input data directly inserted into the HTML code in the rendering code, which may lead to an XSS attack. Through static analysis, the template engine can identify these potential security issues and record their locations and types.
[0150] Step S2200: When there is a target security vulnerability, merge the rendering code with the preset repair prompt text corresponding to the target security vulnerability and input it into the code repair model to start the automatic repair of the rendering code;
[0151] When a target security vulnerability is detected in the rendering code, the template engine will start an automatic repair process. The core of this process is to merge the rendering code with the preset repair prompt text for this security vulnerability and input it into the code repair model. The code repair model can be a mature large language model with the ability to understand and generate code, and can modify the rendering code targeted according to the input repair prompt text to eliminate security vulnerabilities.
[0152] The repair prompt text is generated according to a preset instruction template, and the instruction template defines the specific operations and logic required to repair a specific security vulnerability. For example, for a cross-site scripting (XSS) vulnerability, the instruction template may contain the following content: "Perform HTML escaping on all user input data to ensure that the data is correctly escaped before being inserted into the HTML page." The repair prompt text will generate specific repair code snippets according to this instruction template, such as the code for calling the HTML escaping function.
[0153] After receiving the rendering code and the repair prompt text, the code repair model will parse the vulnerability location in the rendering code and generate the repaired code according to the repair prompt text. For example, if there is unescaped user input data in the rendering code, the code repair model will insert a call to the HTML escaping function at the corresponding location to ensure that the data is correctly processed before being inserted into the HTML page. The repaired code will replace the original rendering code, thus completing the automatic repair process.
[0154] This automatic repair mechanism can not only quickly respond to detected security vulnerabilities, reduce the need for manual intervention, but also ensure the consistency and accuracy of repair measures. Through the preset instruction template and repair prompt text, the code repair model can generate corresponding repair code for different types of vulnerabilities, thus improving the security and reliability of the template engine.
[0155] Step S2300: Iteratively perform a secondary security check on the repaired rendering code, and output an alarm message when the target security vulnerability is detected again.
[0156] After the repair is completed, the template engine will conduct a secondary security check on the repaired rendering code to verify the success of the repair. This iterative checking process ensures the effectiveness of the repair measures. If the target security vulnerability is detected again during the secondary check, the template engine will output an alarm message to notify the developer or system administrator to take further measures. The alarm message can include the specific location, type of the vulnerability, and repair suggestions to help the relevant personnel quickly locate and solve the problem.
[0157] In this embodiment, by introducing a mechanism of the template engine for security check, automatic repair, and secondary verification of the rendering code, the security and reliability of the page server-side rendering are significantly enhanced. First, by static analysis to detect target security vulnerabilities in the rendering code, such as XSS or CSRF, etc., potential security risks can be discovered in advance, avoiding the exploitation of these vulnerabilities, thereby protecting user data and platform security. Second, using the preset repair hint text and code repair model to automatically repair the detected security vulnerabilities reduces the need for manual intervention, improves development efficiency, and ensures the accuracy and consistency of the repair measures. Finally, through iterative security checks to verify the repair effect, ensuring that the vulnerabilities are completely resolved. If the vulnerabilities are detected again, detailed alarm messages will be output to provide a clear repair direction for developers or system administrators, further reducing security risks. Overall, this embodiment not only improves the security of the page but also enhances development and operation and maintenance efficiency through the automatic repair and verification mechanism, providing a more stable and secure page rendering solution for the e-commerce platform.
[0158] Based on any embodiment of the method of the present application, binding the business data obtained from the data source to the corresponding variables in the template file includes:
[0159] Step S3321: Obtain the historical behavior data of the user from the user behavior database according to the user identifier included in the page access request;
[0160] The template engine will obtain the historical behavior data of the user from the user behavior database according to the user identifier included in the page access request. The user identifier can be the user's login ID, Cookie, or other unique identifiers, used to retrieve the user's historical behavior records from the database. These historical behavior data may include the user's browsing history, purchase records, favorite content, search keywords, etc. For example, the e-commerce platform can obtain the product categories browsed by the user and the product information purchased in the past month from the database through the user identifier.
[0161] Step S3322: Call a preset personalized recommendation algorithm according to the historical behavior data to generate a personalized product recommendation list;
[0162] Based on these historical behavior data, the template engine will call the preset personalized recommendation algorithm to generate a personalized product recommendation list. The personalized recommendation algorithm can be implemented based on technologies such as collaborative filtering, content recommendation, or hybrid recommendation. For example, the collaborative filtering algorithm can recommend products according to the user's historical behavior and the preferences of similar users; the content recommendation algorithm can generate a recommendation list according to the attributes of the products and the user's historical interests. These algorithms usually consider multiple factors, such as the user's purchase frequency, browsing duration, ratings, etc., to generate a product recommendation list that best suits the user's interests.
[0163] Step S3323: Format the personalized product recommendation list according to the business data filter preset in the template file;
[0164] After generating the personalized product recommendation list, the template engine will format the recommendation list according to the business data filter preset in the template file. The role of the business data filter is to format, transform, or verify the data in the recommendation list to ensure that the data meets the requirements of the template file. For example, the filter can perform currency formatting on the product price, truncate the length of the product name, or sort the recommendation list. These filters can dynamically adjust the processing logic according to the configuration in the template file or predefined rules to adapt to different display requirements.
[0165] Step S3324: Bind the formatted product recommendation list as business data to the corresponding variables in the template file.
[0166] The template engine binds the formatted product recommendation list as business data to the corresponding variables in the template file. The template file may contain one or more variables for displaying information about the recommended products. For example, there may be a variable recommendedItems in the template file for displaying the recommended product list. The template engine will bind the processed recommendation list to this variable, enabling the dynamic display of personalized product recommendation content during page rendering.
[0167] In this embodiment, through the combination of the template engine, the user's historical behavior data, and the personalized recommendation algorithm, accurate personalized product recommendations are achieved. The recommendation results are formatted through the business data filter, and finally the processed recommendation list is dynamically bound to the corresponding variables in the template file for page rendering. This process not only improves the user experience, enabling users to quickly obtain product recommendations that match their personal interests, but also enhances the commercial value of the e-commerce platform, increasing the user purchase conversion rate and the platform's operation efficiency through accurate recommendations. At the same time, the use of the business data filter ensures the format consistency of the recommendation data, optimizes the page display effect, and further enhances the professionalism and credibility of the platform.
[0168] Based on any embodiment of the method of the present application, the method further includes:
[0169] Step S5100: After receiving a page access request sent by a client in a product rush purchase scenario on an e-commerce platform, sort the requests according to a preset priority rule, and sequentially call a template engine for page rendering according to the sorting;
[0170] In a high-concurrency scenario of an e-commerce platform, such as a product rush purchase event, quickly responding to a client's page access request and efficiently rendering the page is the key to enhancing the user experience and ensuring the smoothness of transactions. For this purpose, the present application proposes an optimized processing mechanism for efficiently processing page access requests sent by clients.
[0171] When the front-end server of an e-commerce platform receives a page access request sent by a client, it sorts these requests according to a preset priority rule. The priority rule can be comprehensively set based on various factors such as the urgency of the request, the user's historical behavior data, and the current server load. For example, in a product rush purchase scenario, requests from high-frequency purchasing users or requests pointing to popular product pages can be preferentially processed to ensure that these critical requests can be responded to more quickly. After sorting, the template engine of the present application is sequentially called according to the sorting result for page rendering to generate the final page code corresponding to each request.
[0172] Step S5200: When the template engine parses the template files corresponding to each request, enable a multi-thread mechanism to parse multiple template files simultaneously;
[0173] To further improve the efficiency of page rendering, when the template engine parses the template files corresponding to each request, a multi-thread mechanism is enabled to achieve simultaneous parsing of multiple template files. By processing multiple template files in parallel, the total time-consuming for template parsing is significantly shortened, thereby accelerating the speed of page rendering.
[0174] Specifically, for the requests sorted out, the template engine assigns a thread to each request to parse the corresponding template file. These threads can run simultaneously without interfering with each other. This multi-thread parsing mechanism not only improves the parsing efficiency of template files but also reduces the user's waiting time for page loading. Especially in a high-concurrency rush purchase scenario, it can significantly enhance the user experience.
[0175] By enabling the multi-threading mechanism to parse multiple template files simultaneously, the template engine can make full use of the multi-core processing power of the server, significantly improve the parsing efficiency of template files, and reduce the waiting time for page rendering. This mechanism is not only applicable to the product rush purchase scenarios of e-commerce platforms, but also can be widely applied to other scenarios that require quick response and efficient processing, such as online ticketing systems, flash sales, etc., providing users with a smoother and faster page loading experience.
[0176] Step S5300: When generating the final page code corresponding to each request, perform caching processing on the static resources in the final page code to reduce repeated requests to the data source;
[0177] When generating the final page code corresponding to each request, the template engine will perform caching processing on the static resources in the final page code to reduce repeated requests to the data source. Static resources refer to resources that do not change frequently during page rendering, such as CSS files, JavaScript files, images, etc. These resources are often the same in multiple page requests, so caching them can significantly improve page loading efficiency and reduce the burden on the server.
[0178] There are various specific implementation methods for caching processing. A common method is to use in-memory caching, storing static resources in the server's memory. When subsequent requests require the same static resources, they can be directly retrieved from the memory without having to load them from the data source again, thus greatly reducing the response time. For example, for the product detail page of an e-commerce platform, its page layout and style are usually controlled by the same CSS files. By caching these CSS files in memory, subsequent page requests can be quickly responded to.
[0179] Another implementation method is to use a distributed caching system, such as Redis or Memcached. These systems can store static resources across multiple server instances and are suitable for e-commerce platforms with a distributed architecture. When a request requires a certain static resource, the template engine first queries the distributed caching system. If the resource exists in the cache, it is directly returned; if not, the resource is loaded from the data source and simultaneously stored in the caching system for subsequent requests to directly use.
[0180] In addition, the content delivery network (CDN) can be combined to further optimize the caching and distribution of static resources. The CDN can cache static resources on edge servers closer to users, thus reducing the latency of user requests for resources. For example, for a global e-commerce platform, by caching images and CSS files on CDN nodes around the world, it can ensure that users can quickly load these resources regardless of their location.
[0181] In practical applications, the caching strategy can be flexibly configured according to the update frequency and importance of resources. For example, for resources that are updated frequently, a shorter caching time can be set; while for resources that rarely change, a longer caching time can be set. At the same time, the template engine can also dynamically adjust the caching usage strategy based on the priority of requests and the user's behavior data to achieve optimal performance optimization.
[0182] Through the above caching processing mechanism, the template engine can not only reduce the repeated requests to the data source, improve the page loading speed, but also effectively reduce the load on the server and enhance the performance and user experience of the entire e-commerce platform.
[0183] Step S5400: After compressing the generated final page code, push it to the corresponding clients for each request.
[0184] After generating the final page code corresponding to each request, the template engine will compress these page codes to reduce the amount of data transferred for the page and speed up the page loading speed. The compression process is achieved by removing redundant information such as extra white space characters, comments, and line breaks in the HTML code, thereby generating more compact HTML code. For example, the original HTML code may contain multi-line comments and multiple consecutive spaces, which will all be removed during the compression process, resulting in a significant reduction in the size of the final HTML file.
[0185] In addition, the template engine can further compress the static resources (such as CSS and JavaScript files) in the page. For example, by merging multiple CSS files or JavaScript files into one file to reduce the number of HTTP requests; or by using tools (such as UglifyJS or CSSNano) to compress the code of these files, removing unnecessary spaces, comments, and redundant code to further reduce the file size. For example, a page containing multiple JavaScript files can be compressed and merged into one file, thereby reducing the time for the browser to load these resources.
[0186] After completing the compression process, the template engine pushes the optimized page code to the corresponding clients for each request. This process can be achieved through various technologies. For example, using the HTTP / 2 protocol for page pushing, which supports multiplexing and server push functions and can significantly improve the page loading speed. The server push function allows the server to pre-push the page code and related resources to the client before the client requests the page, thereby reducing the client waiting time. For example, when the client requests a product details page, the server can pre-push the HTML code, CSS file, and JavaScript file of this page, enabling the client to load and render the page faster.
[0187] In this embodiment, through a series of optimization measures, the page rendering efficiency and user experience of the e-commerce platform in high-concurrency scenarios have been significantly improved. First, the page access requests of the client are sorted according to preset priority rules to ensure that key requests (such as requests for high-frequency purchasing users or popular commodity pages) can obtain faster responses, thus ensuring the smoothness of transactions. Secondly, the template engine enables a multi-threaded mechanism to parse multiple template files simultaneously, making full use of the multi-core processing power of the server, significantly shortening the template parsing time, and accelerating the page rendering speed. In addition, the static resources in the final page code are cached to reduce repeated requests to the data source, relieve the server burden, and at the same time, the resource distribution is further optimized through flexible caching policies and CDN technology to improve the page loading efficiency. Finally, the generated final page code is compressed to further reduce the amount of transmitted data. Combining the multiplexing and server push functions of the HTTP / 2 protocol, the page code is quickly pushed to the client, significantly accelerating the page loading speed. These measures work together not only to improve the user experience but also to enhance the stability and reliability of the e-commerce platform in high-concurrency scenarios, providing an efficient page rendering solution for the e-commerce platform.
[0188] Please refer to Figure 3 , a page server-side rendering device provided according to an aspect of the present application includes an engine invocation module 3100, a template parsing module 3200, a template rendering module 3300, and a page output module 3400. Among them, the engine invocation module 3100 is configured to respond to a page access request sent by the client, and according to the page identifier of the page to be accessed included in the request, call a template engine developed based on a compiled language to obtain a corresponding template file according to the page identifier; the template parsing module 3200 is configured to parse the template file by the template engine to generate a corresponding abstract syntax tree, and the abstract syntax tree represents the logical relationship information among the mixed operation expressions, variable scopes, custom tags, business data filters, and control statements in the template file; the template rendering module 3300 is configured to statically verify and optimize the logical relationship information in the template file based on the abstract syntax tree by the template engine, and bind the business data obtained from the data source to the corresponding variables in the template file to obtain optimized rendering code; the page output module 3400 is configured to generate and remove redundant information from the final page code by the template engine, and send the final page code to the client for rendering and display.
[0189] Based on any embodiment of the device in the present application, the template rendering module 3300 includes any one or more of the following modules: an expression verification module, configured to perform precedence parsing and syntax verification on the mixed operation expressions in the template file to determine that the mixed operation expressions conform to the operation rules; a scope verification module, configured to verify based on the scope chain of variables established during the template file parsing stage and represented in the abstract syntax tree to determine that the definition and call of variables conform to their scope rules; a tag verification module, configured to perform semantic verification on custom tags to determine whether the custom tags conform to the custom rules; a filter verification module, configured to verify the call interface of the business data filter to determine that the call interface of the filter conforms to the custom rules, where the business data filter is used to process business data to bind it to corresponding variables; a statement verification module, configured to verify the syntax and logical structure of control statements to determine that the expression of the control statements conforms to the preset language rules.
[0190] Based on any embodiment of the device in the present application, the template rendering module 3300 includes: a data acquisition module, configured to acquire business data related to the page to be accessed from a data source according to the correspondence between variables and business data; a data filtering module, configured to call a business data filter to process the business data, where the business data filter is used to format, convert, or verify business data; a variable assignment module, configured to bind the data processed by the business data filter to the corresponding variables in the template file to generate variable values available for rendering.
[0191] Based on any embodiment of the device in the present application, the page output module 3400 includes: a code generation module, configured to generate HTML code for the page to be accessed according to the optimized rendering code; a redundancy optimization module, configured to perform optimization processing on the HTML code to remove whitespace characters and comments that constitute redundant information; a page push module, configured to send the optimized HTML code as the final page code to the client for rendering and display.
[0192] Based on any embodiment of the device in the present application, prior to the page output module 3400, there is also included: a vulnerability detection module, configured to perform a security check on the rendering code to detect whether there are target security vulnerabilities; an automatic repair module, configured to, when there are target security vulnerabilities, input the rendering code merged with the corresponding preset repair prompt text for the target security vulnerabilities into a code repair model to initiate automatic repair of the rendering code; a vulnerability recheck module, configured to iteratively perform a secondary security check on the repaired rendering code and output an alarm message when the target security vulnerabilities are detected again.
[0193] Based on any embodiment of the device in the present application, the template rendering module 3300 includes: a data calling module configured to obtain the historical behavior data of the user from the user behavior database according to the user identifier included in the page access request; a product recommendation module configured to call a preset personalized recommendation algorithm according to the historical behavior data to generate a personalized product recommendation list; a list filtering module configured to perform formatting processing on the personalized product recommendation list according to the business data filter preset in the template file; and a variable binding module configured to bind the formatted product recommendation list as business data to the corresponding variables in the template file.
[0194] Based on any embodiment of the device in the present application, the device further includes: a request queuing module configured to, after receiving a page access request sent by a client in a scenario of snapping up products on an e-commerce platform, sort the requests according to a preset priority rule and sequentially call a template engine to perform page rendering; a parallel processing module configured to enable a multi-thread mechanism to simultaneously parse multiple template files when the template engine parses the template files corresponding to each request; a cache processing module configured to perform cache processing on the static resources in the final page code when generating the final page code corresponding to each request to reduce repeated requests to the data source; and a compression transmission module configured to perform compression processing on the generated final page code and then push it to the corresponding clients of each request.
[0195] Another embodiment of the present application further provides a page server-side rendering device. As Figure 4 shown, it is a schematic internal structure diagram of the page server-side rendering device. The page server-side rendering device includes a processor, a computer-readable storage medium, a memory, and a network interface connected through a system bus. Among them, the computer-readable non-volatile storage medium of the page server-side rendering device stores an operating system, a database, and computer-readable instructions. The database may store an information sequence. When the computer-readable instructions are executed by the processor, the processor can implement a page server-side rendering method.
[0196] The processor of the page server-side rendering device is used to provide computing and control capabilities to support the operation of the entire page server-side rendering device. The memory of the page server-side rendering device may store computer-readable instructions. When the computer-readable instructions are executed by the processor, the processor can execute the page server-side rendering method of the present application. The network interface of the page server-side rendering device is used to connect and communicate with the terminal.
[0197] Those skilled in the art can understand, Figure 4The structure shown is only a block diagram of some structures related to the solution of this application, and does not constitute a limitation on the page server rendering device to which the solution of this application is applied. The specific page server rendering device may include more or fewer components than those shown in the figure, or combine some components, or have different component arrangements.
[0198] In this embodiment, the processor is used to execute Figure 3 the specific functions of each module in. The memory stores the program codes and various types of data required to execute the above modules or sub-modules. The network interface is used to implement data transmission between user terminals or servers. In this embodiment, the non-volatile readable storage medium stores the program codes and data required to execute all modules in the page server rendering device of this application, and the server can call the program codes and data of the server to execute the functions of all modules.
[0199] This application also provides a non-volatile readable storage medium storing computer-readable instructions. When the computer-readable instructions are executed by one or more processors, the one or more processors are caused to execute the steps of the page server rendering method according to any embodiment of this application.
[0200] This application also provides a computer program product, including computer programs / instructions. When the computer programs / instructions are executed by one or more processors, the steps of the method according to any embodiment of this application are implemented.
[0201] Those of ordinary skill in the art can understand that to implement all or part of the processes in the methods of the above embodiments of this application, it can be completed by instructing relevant hardware through a computer program. The computer program can be stored in a non-volatile readable storage medium. When the program is executed, it may include the processes of the embodiments of the above methods. Among them, the aforementioned storage medium may be a computer-readable storage medium such as a magnetic disk, an optical disc, a read-only memory (ROM), or a random access memory (RAM), etc.
[0202] In summary, this application not only improves the performance and security of the page, but also enhances the user experience by optimizing the page code, providing significant technical advantages for application requirements such as e-commerce platforms and email promotions in the fierce market competition.
Claims
1. A page server rendering method, characterized in that: include: In response to a page access request sent by a client, according to a page identifier of a page to be accessed contained in the request, a template engine developed based on a compiled language is called to obtain a corresponding template file according to the page identifier; The template engine parses the template file to generate a corresponding abstract syntax tree, which represents the mixed operation expressions, variable scopes, custom tags, business data filters and logical relationship information between control statements in the template file; The template engine performs static verification optimization on the logical relationship information in the template file based on the abstract syntax tree, binds the business data obtained from the data source to the corresponding variables in the template file according to the corresponding relationship between the variables and the business data, and obtains the optimized rendering code; The template engine generates a final page code based on the rendering code and removes redundant information, and sends the final page code to the client for rendering and display.
2. The page server rendering method according to claim 1, characterized in that: Static verification optimization is performed on the logical relationship information in the template file, including any one or more of the following: Perform priority parsing and syntax checking on mixed operation expressions in template files to ensure that the mixed operation expressions comply with operation rules; Based on the scope chain of the variables established in the template file parsing phase and represented in the abstract syntax tree, verifying and determining whether the definition and call of the variables comply with the scope rules thereof; Perform semantic verification on custom tags to determine whether the custom tags comply with custom rules; Verify the calling interface of the business data filter to determine whether the calling interface of the filter complies with the custom rules, wherein the business data filter is used to process the business data to bind with the corresponding variable; Check the syntax and logical structure of the control statement to ensure that the expression of the control statement conforms to the preset language rules.
3. The page server rendering method according to claim 2, characterized in that: Bind the business data obtained from the data source to the corresponding variables in the template file, including: According to the corresponding relationship between the variable and the business data, the business data related to the page to be visited is obtained from the data source; Calling a business data filter to process the business data, wherein the business data filter is used to format, convert or verify the business data; Bind the data processed by the business data filter to the corresponding variables in the template file to generate variable values that can be used for rendering.
4. The page server rendering method according to claim 1, characterized in that: The template engine generates a final page code according to the rendering code and removes redundant information, and sends the final page code to the client for rendering and display, including: Generate HTML code of the page to be visited based on the optimized rendering code; Optimize HTML code to remove blank characters and comments that constitute redundant information; The optimized HTML code is sent to the client as the final page code for rendering and display.
5. The page server rendering method according to claim 1, characterized in that: Before the template engine generates and removes redundant information according to the rendering code to obtain the final page code, the method further includes: Performing a security check on the rendering code to detect whether there is a target security vulnerability; When a target security vulnerability exists, the rendering code is merged with the preset repair prompt text corresponding to the target security vulnerability and input into the code repair model to start automatic repair of the rendering code; Iteratively perform a secondary security check on the repaired rendering code, and output a warning message when the target security vulnerability is detected again.
6. The page server rendering method according to claim 1, characterized in that: Bind the business data obtained from the data source to the corresponding variables in the template file, including: Acquiring historical behavior data of the user from a user behavior database according to the user identifier included in the page access request; Based on the historical behavior data, a preset personalized recommendation algorithm is called to generate a personalized product recommendation list; Formatting the personalized product recommendation list according to the business data filter preset in the template file; The formatted product recommendation list is used as business data and bound to the corresponding variables in the template file.
7. The page server rendering method according to any one of claims 1 to 6, characterized in that: The method further comprises: After receiving page access requests sent by clients in the e-commerce platform product rush purchase scenario, the requests are sorted according to the preset priority rules, and the template engine is called in sequence to render the page according to the sorting; When the template engine parses the template files corresponding to each request, it enables the multi-threading mechanism to parse multiple template files at the same time; When generating the final page code corresponding to each request, the static resources in the final page code are cached to reduce repeated requests to the data source; The generated final page code is compressed and pushed to the corresponding client of each request.
8. A page server rendering device, characterized in that: include: The engine calling module is configured to respond to a page access request sent by a client, and according to a page identifier of a page to be accessed contained in the request, call a template engine developed based on a compiled language to obtain a corresponding template file according to the page identifier; A template parsing module, configured to parse the template file by the template engine to generate a corresponding abstract syntax tree, wherein the abstract syntax tree represents the mixed operation expressions, variable scopes, custom tags, business data filters, and logical relationship information between control statements in the template file; The template rendering module is configured to perform static verification optimization on the logical relationship information in the template file based on the abstract syntax tree by the template engine, bind the business data obtained from the data source to the corresponding variables in the template file, and obtain the optimized rendering code; The page output module is configured to generate a final page code by the template engine according to the rendering code and remove redundant information, and send the final page code to the client for rendering and display.
9. A page server rendering device, comprising a central processing unit and a memory, characterized in that: The central processing unit is used to call and run the computer program stored in the memory to execute the steps of the method according to any one of claims 1 to 7.
10. A non-volatile readable storage medium, characterized in that: It stores a computer program implemented according to the method described in any one of claims 1 to 7 in the form of computer-readable instructions, and when the computer program is called and executed by a computer, the steps included in the corresponding method are executed.