CN107357817B - It is a kind of towards the Web page module design of JSON and its Asynchronous loading method - Google Patents
It is a kind of towards the Web page module design of JSON and its Asynchronous loading method Download PDFInfo
- Publication number
- CN107357817B CN107357817B CN201710427924.3A CN201710427924A CN107357817B CN 107357817 B CN107357817 B CN 107357817B CN 201710427924 A CN201710427924 A CN 201710427924A CN 107357817 B CN107357817 B CN 107357817B
- Authority
- CN
- China
- Prior art keywords
- web page
- page layout
- objects
- layout
- webpage
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
Classifications
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/90—Details of database functions independent of the retrieved data types
- G06F16/95—Retrieval from the web
- G06F16/957—Browsing optimisation, e.g. caching or content distillation
- G06F16/9577—Optimising the visualization of content, e.g. distillation of HTML documents
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F40/00—Handling natural language data
- G06F40/10—Text processing
- G06F40/12—Use of codes for handling textual entities
- G06F40/14—Tree-structured documents
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F8/00—Arrangements for software engineering
- G06F8/30—Creation or generation of source code
- G06F8/38—Creation or generation of source code for implementing user interfaces
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- General Engineering & Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- Databases & Information Systems (AREA)
- Software Systems (AREA)
- Computational Linguistics (AREA)
- General Health & Medical Sciences (AREA)
- Health & Medical Sciences (AREA)
- Audiology, Speech & Language Pathology (AREA)
- Artificial Intelligence (AREA)
- Data Mining & Analysis (AREA)
- Human Computer Interaction (AREA)
- Information Transfer Between Computers (AREA)
Abstract
本发明公开了一种面向JSON的网页模块化设计及其异步加载方法,HTML网页布局及网页元素被封装成不同的JSON对象,这些JSON对象相对独立又可以嵌套定义,从而可以方便实现网页的模块化设计及动态修改;使用JSON对象表示HTML网页布局和网页元素可以进一步降低数据冗余,提高网页代码的网络传输和响应速度。本发明的方法适用于Web软件设计,在软件开发领域有重要的应用价值。
The invention discloses a JSON-oriented webpage modular design and its asynchronous loading method. HTML webpage layouts and webpage elements are encapsulated into different JSON objects. Modular design and dynamic modification; using JSON objects to represent HTML webpage layout and webpage elements can further reduce data redundancy and improve network transmission and response speed of webpage codes. The method of the invention is suitable for Web software design and has important application value in the field of software development.
Description
技术领域technical field
本发明涉及计算机网络技术领域,具体涉及一种面向JSON的网页模块化设计及其异步加载方法。The invention relates to the technical field of computer networks, in particular to a JSON-oriented web page modular design and an asynchronous loading method thereof.
背景技术Background technique
JavaScript Object Notation(即JSON)是JavaScript编程语言中定义的一种语法单元,目前常被用做一种轻量级的数据交换格式。JSON可被表示成一组文本格式的名称-值对的集合,其独立于具体编程语言,可被大多数常用编程语言解析和自动生成;JSON语法简洁,不存在数据冗余,可以大大提高传输与响应速度。JSON使用方便,特别是在进行Web前端开发时,JSON格式的数据经过JavaScript的eval方法即可转换成JavaScript内部对象供程序调用,其转换方法在不同内核的浏览器内部是定义好的而且统一的,不需要手工编写,也不需要考虑不同内核浏览器的差异性。Web服务器端常用的语言也都提供相应的JSON解析器,可以很方便的解析客户端传过来的JSON格式的数据,而不需要借助于其它的API工具。JavaScript Object Notation (JSON) is a grammatical unit defined in the JavaScript programming language, and is currently often used as a lightweight data exchange format. JSON can be expressed as a set of name-value pairs in text format, which is independent of specific programming languages and can be parsed and automatically generated by most common programming languages; JSON syntax is concise and there is no data redundancy, which can greatly improve transmission and communication. responding speed. JSON is easy to use, especially in web front-end development, the data in JSON format can be converted into JavaScript internal objects for program calls through the eval method of JavaScript. The conversion method is defined and unified in browsers with different cores , does not need to be manually written, and does not need to consider the differences of different kernel browsers. The languages commonly used on the web server side also provide corresponding JSON parsers, which can easily parse the data in JSON format sent by the client without resorting to other API tools.
在一个典型的Web应用中,根据Web客户端的请求报文,Web服务器端通常需要动态生成HTML网页代码作为响应报文并通过网络返回给Web客户端。然而,传统方式生成HTML网页代码被当作一个长字符串处理,字符串的解析相对繁琐,当需要修改某个网页元素时,仅仅在字符串中定位相应的HTML标签以及标签属性就会非常困难;同时,在以字符串形式表示的HTML代码中修改网页布局或网页结构也会非常困难;另外,以字符串形式表示的HTML代码存在大量数据冗余,例如每个网页元素均需要包括起始标签和终止标签,将字符串形式的HTML代码直接在网络中传输,会降低网络通信的传输和响应速度。因此,Web应用开发领域迫切需要一种更加高效的网页表示及设计方式。In a typical web application, according to the request message of the web client, the web server usually needs to dynamically generate HTML webpage code as a response message and return it to the web client through the network. However, the traditional way to generate HTML web page code is treated as a long string, and the parsing of the string is relatively cumbersome. When a web page element needs to be modified, it is very difficult to locate the corresponding HTML tags and tag attributes in the string. ; At the same time, it will be very difficult to modify the layout or structure of the web page in the HTML code expressed in string form; in addition, there is a lot of data redundancy in the HTML code expressed in string form, for example, each web page element needs to include the start Tags and termination tags transmit HTML codes in the form of strings directly on the network, which will reduce the transmission and response speed of network communications. Therefore, a more efficient way of representing and designing web pages is urgently needed in the field of web application development.
发明内容Contents of the invention
针对上述现有技术中存在的问题,本发明的目的在于,提供一种面向JSON的网页模块化设计及其异步加载方法,以克服现有网页设计方法中生成的HTML代码解析困难、修改困难和数据冗余等缺陷,实现了利用JSON对象的方式对网页进行模块化设计并进行异步加载。In view of the problems existing in the above-mentioned prior art, the object of the present invention is to provide a JSON-oriented web page modular design and an asynchronous loading method thereof, so as to overcome the difficulty in parsing and modifying the HTML code generated in the existing web page design method and Data redundancy and other defects, realize the modular design and asynchronous loading of web pages by using JSON objects.
为了实现上述任务,本发明采用以下技术方案:In order to achieve the above tasks, the present invention adopts the following technical solutions:
一种面向JSON的网页模块化设计及其异步加载方法,包括以下步骤:A JSON-oriented web page modular design and its asynchronous loading method, comprising the following steps:
步骤一,确定网页的布局结构,以及布局结构中各个部分所需要包含的网页元素;Step 1, determine the layout structure of the webpage, and the webpage elements that need to be included in each part of the layout structure;
步骤二,根据步骤一确定的网页布局结构和网页元素,使用JSON对象的形式定义网页布局模板以及相应的网页元素;所述的网页布局模板中包括网页布局容器以及网页布局条目这两类组件;Step 2, according to the webpage layout structure and webpage elements determined in step 1, define a webpage layout template and corresponding webpage elements in the form of JSON objects; the webpage layout template includes two types of components: webpage layout container and webpage layout entry;
步骤三,将定义的网页布局容器、网页布局条目和网页元素组装成网页JSON对象;Step 3, assembling the defined webpage layout container, webpage layout items and webpage elements into a webpage JSON object;
步骤四,创建一个HTML DOM对象类型的全局等待队列;Step 4, create a global waiting queue of HTML DOM object type;
步骤五,遍历JSON对象的template.childs属性中的所有对象,在遍历过程中判断当前对象是网页布局模板还是网页元素,然后根据判断结果执行步骤六或步骤七;当遍历完成时,转向步骤十;Step 5: traverse all objects in the template.childs property of the JSON object, judge whether the current object is a webpage layout template or a webpage element during the traversal process, and then perform step 6 or 7 according to the judgment result; when the traversal is completed, turn to step 10 ;
步骤六,如果是网页布局模板,则继续遍历其childs属性中的所有对象,并保存遍历每个对象时所生成的HTML DOM对象,直到遍历完成时,根据返回的所有HTML DOM对象,以及当前网页布局模板的component属性,生成网页布局模板对应的HTML DOM对象,然后返回步骤五;Step 6, if it is a web page layout template, continue to traverse all objects in its childrens property, and save the HTML DOM objects generated when traversing each object, until the traversal is complete, according to all returned HTML DOM objects, and the current web page The component attribute of the layout template generates the HTML DOM object corresponding to the layout template of the web page, and then returns to step 5;
步骤七,如果是网页元素,则检测该网页元素scriptAddr属性对应的脚本代码是否加载完成,如果加载完成,则执行该脚本代码,创建该网页元素对应的HTML DOM对象并返回给它的上一级网页布局模板,并返回步骤六;否则,执行步骤八;Step 7, if it is a web page element, check whether the script code corresponding to the scriptAddr attribute of the web page element is loaded, and if it is loaded, execute the script code, create the HTML DOM object corresponding to the web page element and return it to its upper level Web page layout template, and return to step six; otherwise, go to step eight;
步骤八,判断是否已经创建和当前网页元素对应的script对象,如果是则返回一个空的HTML DOM对象给它的上一级网页布局模板,并返回步骤六;否则,执行步骤九;Step 8, determine whether the script object corresponding to the current web page element has been created, if so, return an empty HTML DOM object to its upper-level web page layout template, and return to step 6; otherwise, execute step 9;
步骤九,创建和当前网页元素对应的script对象,并将当前网页元素scriptAddr属性的值赋值给该script对象的src属性,将该script对象加入步骤四中创建的全局等待队列中,然后返回一个空的HTML DOM对象给它的上一级网页布局模板,并返回步骤六;Step 9: Create a script object corresponding to the current web page element, assign the value of the scriptAddr attribute of the current web page element to the src attribute of the script object, add the script object to the global waiting queue created in step 4, and return an empty HTML DOM object to its parent page layout template, and return to step six;
步骤十,调用Web浏览器提供的网页渲染引擎接口,渲染步骤六中已创建的网页布局模板及其中包含的HTML DOM对象;Step ten, call the web page rendering engine interface provided by the web browser, and render the web page layout template created in step six and the HTML DOM objects contained therein;
步骤十一,检测所述的全局等待队列是否为空,如果是则网页所有内容加载完成,则退出本方法;否则执行步骤十二;Step 11, detecting whether the global waiting queue is empty, if yes, all the content of the web page is loaded, then exit the method; otherwise, execute step 12;
步骤十二,检测全局等待队列中是否存在已完成加载的script对象,如果有,则从队列中删除该script对象,并返回步骤十一;否则,执行步骤十三;Step 12, detect whether there is a script object that has been loaded in the global waiting queue, if so, delete the script object from the queue, and return to step 11; otherwise, execute step 13;
步骤十三,监听全局等待队列中位于队列首部的script对象的onload事件发生,当该script对象的onload事件发生后,则返回步骤五。Step 13, monitor the occurrence of the onload event of the script object at the head of the queue in the global waiting queue, and return to step 5 when the onload event of the script object occurs.
进一步地,所述的步骤二中,网页的各个板块的布局模板用网页布局条目定义,网页布局条目必须定义在网页布局容器中。Further, in the second step, the layout templates of each section of the web page are defined by web page layout items, and the web page layout items must be defined in the web page layout container.
进一步地,所述的步骤三中,组装的规则是:网页布局条目必须定义在网页布局容器的childs属性中,一个网页布局容器中可定义多个网页布局条目;网页元素必须定义在网页布局条目的childs属性中,一个网页元素对应一个网页布局条目;在网页布局条目的childs属性中还可以进一步嵌套定义网页布局容器。Further, in step 3, the assembly rule is: the web page layout item must be defined in the children attribute of the web page layout container, multiple web page layout items can be defined in a web page layout container; web page elements must be defined in the web page layout item In the childrens attribute of a webpage element corresponds to a webpage layout entry; in the childrens attribute of a webpage layout entry, a webpage layout container can be further nested.
本发明与现有技术相比具有以下技术特点:Compared with the prior art, the present invention has the following technical characteristics:
1.本发明使用JSON对象表示HTML网页布局和网页元素,网页布局模板及网页元素被封装成不同的JSON对象,这些JSON对象相对独立又可以嵌套定义,从而可以方便实现网页的动态修改;1. The present invention uses JSON object to represent HTML webpage layout and webpage element, and webpage layout template and webpage element are encapsulated into different JSON objects, and these JSON objects are relatively independent and can be nested definition, thereby can realize the dynamic modification of webpage conveniently;
2.使用JSON对象表示HTML网页布局和网页元素可以进一步降低数据冗余,提高网页代码的网络传输和响应速度。本发明的方法适用于Web软件设计,在软件开发领域有重要的应用价值。2. Using JSON objects to represent HTML web page layout and web page elements can further reduce data redundancy and improve the network transmission and response speed of web page codes. The method of the invention is suitable for web software design and has important application value in the field of software development.
附图说明Description of drawings
图1为本发明方法的流程图;Fig. 1 is the flowchart of the inventive method;
具体实施方式Detailed ways
本发明使用JSON对象表示HTML网页布局和网页元素,利用JavaScript程序设计语言自带的解析功能,可以将网页JSON对象直接转化成JavaScript语言的内部对象,从而降低了网页代码的解析难度;面向JSON进行网页设计时,采用模块化设计思想,网页布局模板及网页元素被封装成不同的JSON对象,这些JSON对象相对独立又可以嵌套定义,从而可以方便实现网页的动态修改;HTML网页采用JSON对象的形式表示可以进一步降低数据冗余,提高网页代码的网络传输和响应速度。本发明的详细步骤如下:The present invention uses JSON objects to represent HTML web page layout and web page elements, and uses the parsing function of JavaScript programming language to directly convert web page JSON objects into internal objects of JavaScript language, thereby reducing the parsing difficulty of web page codes; When designing web pages, modular design ideas are adopted. Web page layout templates and web page elements are encapsulated into different JSON objects. These JSON objects are relatively independent and can be nested and defined, so that dynamic modification of web pages can be easily realized; HTML web pages use JSON object Formal representation can further reduce data redundancy and improve network transmission and response speed of web page code. Detailed steps of the present invention are as follows:
步骤一,设计人员确定网页布局结构,以及网页布局结构中各个部分所包含的网页元素。网页布局结构是指HTML网页被划分的各个版块、各个板块的尺寸和各个板块之间的相对位置,常见的网页布局结构包括上下布局结构、左右布局结构、田字形布局结构等等。所述的网页元素是指在HTML网页的某个版块中使用到的HTML标签元素,常见的有div、span和table等HTML标签。Step 1, the designer determines the layout structure of the webpage and the webpage elements contained in each part of the layout structure of the webpage. The layout structure of a web page refers to the divisions of HTML web pages, the size of each board, and the relative position between each board. The web page element refers to an HTML tag element used in a certain section of an HTML web page, and common HTML tags include div, span, and table.
步骤二,根据步骤一确定的网页布局结构以及确定的网页元素,使用JSON对象的形式定义网页布局模板,并使用JSON对象的形式定义相应的网页元素;Step 2, according to the web page layout structure and determined web page elements determined in step 1, define a web page layout template in the form of a JSON object, and define corresponding web page elements in the form of a JSON object;
网页布局模板中包括了template-container和template-item两类组件,其中template-container为网页布局容器,template-item为网页布局条目;网页的各个版块的布局模板用template-item定义,template-item必须定义在template-container中;根据网页布局结构,一个template-container中可定义多个template-item。The web page layout template includes two types of components, template-container and template-item, where template-container is the web page layout container, and template-item is the web page layout item; the layout templates of each section of the web page are defined by template-item, and template-item It must be defined in the template-container; according to the layout structure of the web page, multiple template-items can be defined in one template-container.
所述的网页布局模板以JSON对象的方式表示,如下式所示:The web page layout template is expressed in the form of a JSON object, as shown in the following formula:
{"name":"","version":"","template":Object{...}} (1){"name":"","version":"","template":Object{...}} (1)
其中,name为String类型,表示布局模板名称;version为String类型,表示网页布局模板的版本号;template为JSON对象类型,表示网页布局模板中的对象,template-container被定义在该属性中。Among them, name is a String type, indicating the layout template name; version is a String type, indicating the version number of the web page layout template; template is a JSON object type, indicating the object in the web page layout template, and template-container is defined in this attribute.
所述的网页布局容器template-container以JSON对象的方式表示,如下式所示:The web page layout container template-container is expressed in the form of a JSON object, as shown in the following formula:
其中,component为String类型,表示布局容器使用的HTML标签名,如div、span等;props为JSON对象类型,其中定义了className属性,className为String类型,表示该布局模板组件的类型,此处定义为"template-container";childs为数组类型,数组元素中的template属性为JSON对象类型,网页布局条目template-item被定义在该属性中。Among them, component is of String type, indicating the HTML tag name used by the layout container, such as div, span, etc.; props is of JSON object type, which defines the className attribute, className is of String type, indicating the type of the layout template component, defined here is "template-container"; children is an array type, the template attribute in the array element is a JSON object type, and the template-item of the webpage layout item is defined in this attribute.
所述的网页布局条目template-item以JSON对象的方式表示,如下式所示:The web page layout entry template-item is expressed in the form of a JSON object, as shown in the following formula:
其中,component为String类型,表示布局条目使用的HTML标签名,如div、span等;props为JSON对象类型,其中定义了className和style属性,className为String类型,表示该布局模板组件的类型,此处定义为"template-item",style为String类型,表示该布局条目在网页上显示式的渲染属性,可用CSS样式规则的方式进行定义;childs为数组类型,其中保存在该布局条目中的网页元素JSON对象。Among them, component is of String type, indicating the HTML tag name used by layout items, such as div, span, etc.; props is of JSON object type, which defines the className and style attributes, and className is of String type, indicating the type of the layout template component. is defined as "template-item", and style is a String type, which indicates the rendering attribute of the layout item displayed on the web page, which can be defined in the form of CSS style rules; children is an array type, and the web pages stored in the layout item Element JSON object.
所述的网页元素以JSON对象的方式表示,如下式所示:The web page elements are expressed in the form of JSON objects, as shown in the following formula:
其中,name为String类型,表示网页元素名称;version为String类型,表示网页元素的版本号;scriptAddr为String类型,表示解析网页元素的JavaScript脚本代码的URL地址,该代码根据网页元素的props属性数据动态生成HTML DOM对象;props为JSON对象类型,表示网页元素属性,包括src和text等内部成员,其中src为String类型,表示网页元素引用资源的URL地址,text为String类型,表示对网页元素的文字描述;hashName为String类型,表示网页元素的Hash值。Among them, name is of String type, indicating the name of the webpage element; version is of String type, indicating the version number of the webpage element; scriptAddr is of String type, indicating the URL address of the JavaScript script code that parses the webpage element, and the code is based on the props attribute data of the webpage element Dynamically generate HTML DOM objects; props is a JSON object type, indicating the properties of web page elements, including internal members such as src and text, where src is of String type, indicating the URL address of the resource referenced by the web page element, and text is of String type, indicating the URL address of the web page element Text description; hashName is of String type, indicating the Hash value of the web page element.
步骤三,将定义的网页布局容器、网页布局条目和网页元素组装成网页JSON对象;组装的规则是:网页布局条目必须定义在网页布局容器的childs属性中,一个网页布局容器中可定义多个网页布局条目;网页元素必须定义在网页布局条目的childs属性中,一个网页元素对应一个网页布局条目;在网页布局条目的childs属性中还可以进一步嵌套定义网页布局容器。组装过程通过下面的示例进行进一步说明。Step 3, assemble the defined webpage layout container, webpage layout items and webpage elements into a webpage JSON object; the assembly rules are: webpage layout entries must be defined in the children attribute of the webpage layout container, and multiple webpage layout containers can be defined A webpage layout entry; webpage elements must be defined in the children attribute of a webpage layout entry, and a webpage element corresponds to a webpage layout entry; the webpage layout container can be further nested in the children attribute of a webpage layout entry. The assembly process is further illustrated with the example below.
例如,对于一个上下结构的网页,其上部和下部分别包含一个网页元素。上述网页对应的JSON对象如下所示:For example, for a web page with a top-down structure, its upper part and lower part respectively contain a web page element. The JSON object corresponding to the above web page is as follows:
所述的网页中,上下两个网页布局条目的相对位置分别由网页布局条目中的props属性中的style属性中定义的CSS样式规则控制。网页元素scriptAddr属性中定义的JavaScript脚本代码主要是利用Web浏览器提供的接口生成网页元素对应的HTML DOM对象。In the web page, the relative positions of the upper and lower web page layout items are respectively controlled by the CSS style rules defined in the style attribute in the props attribute of the web page layout item. The JavaScript script code defined in the scriptAddr attribute of the webpage element mainly uses the interface provided by the web browser to generate the HTML DOM object corresponding to the webpage element.
步骤四,从本步骤开始将实现对上述网页JSON对象的异步加载过程。首先创建一个HTML DOM对象类型的全局等待队列,全局等待队列为JavaScript的Array类型,Array中的元素均为HTML DOM对象。利用JavaScript语言的特性,所述的全局等待队列中元素的索引可以用String表示。Step 4, starting from this step, the asynchronous loading process of the above-mentioned web page JSON object will be realized. First, create a global waiting queue of HTML DOM object type. The global waiting queue is an Array type of JavaScript, and the elements in the Array are all HTML DOM objects. Using the characteristics of the JavaScript language, the index of the element in the global waiting queue can be represented by String.
步骤五,遍历JSON对象的template.childs属性中的所有对象,在遍历过程中判断当前对象是网页布局模板还是网页元素,然后根据判断结果执行步骤六或步骤七;当遍历完成时,转向步骤十;Step 5: traverse all objects in the template.childs property of the JSON object, judge whether the current object is a webpage layout template or a webpage element during the traversal process, and then perform step 6 or 7 according to the judgment result; when the traversal is completed, turn to step 10 ;
步骤六,如果是网页布局模板,则继续遍历其childs属性中的所有对象,并保存遍历每个对象时所生成的HTML DOM对象,直到遍历完成时,根据返回的所有HTML DOM对象,以及当前网页布局模板的component属性,生成网页布局模板对应的HTML DOM对象,然后返回步骤五;Step 6, if it is a web page layout template, continue to traverse all objects in its childrens property, and save the HTML DOM objects generated when traversing each object, until the traversal is complete, according to all returned HTML DOM objects, and the current web page The component attribute of the layout template generates the HTML DOM object corresponding to the layout template of the web page, and then returns to step 5;
所述的生成网页布局模板对应的HTML DOM对象是通过Web浏览器的DOM接口函数document.createDocumentFragment()创建,该网页布局模板中包含了遍历其childs属性中所有对象时所返回的所有HTML DOM对象,以及该网页布局模板的component属性所指定的HTML DOM对象。The HTML DOM object corresponding to the generated web page layout template is created by the DOM interface function document.createDocumentFragment() of the web browser, and the web page layout template includes all HTML DOM objects returned when traversing all objects in its childrens attribute , and the HTML DOM object specified by the component attribute of the page layout template.
所述的遍历网页布局模板的childs属性中的所有对象所生成的HTML DOM对象,通过Web浏览器的DOM接口函数document.createDocumentFragment().appendChild()添加到网页布局模板对应的HTML DOM对象中。The HTML DOM object generated by traversing all objects in the childrens attribute of the web page layout template is added to the HTML DOM object corresponding to the web page layout template through the DOM interface function document.createDocumentFragment().appendChild() of the web browser.
步骤七,如果是网页元素,则检测该网页元素scriptAddr属性对应的脚本代码是否加载完成,如果加载完成,则执行该脚本代码,创建该网页元素对应的HTML DOM对象并返回给它的上一级网页布局模板,并返回步骤六;否则,执行步骤八;所述的创建网页元素对应的HTML DOM对象,是通过调用Web浏览器的DOM接口函数document.createElement()实现的,其中所创建的网页元素对应的HTML DOM对象以网页元素hashName属性值命名。Step 7, if it is a web page element, check whether the script code corresponding to the scriptAddr attribute of the web page element is loaded, and if it is loaded, execute the script code, create the HTML DOM object corresponding to the web page element and return it to its upper level Web page layout template, and return to step six; otherwise, perform step eight; the described creation of the corresponding HTML DOM object of the web page element is realized by calling the DOM interface function document.createElement () of the web browser, wherein the created web page The HTML DOM object corresponding to the element is named after the hashName attribute value of the web page element.
检测网页元素scriptAddr属性对应的脚本代码是否加载完成是通过如下方式完成的:检测Web浏览器的window对象包含的DOM对象集合中是否已经包含名称为网页元素hashName属性值的DOM对象;如已包含该DOM对象,则相应的脚本代码已经加载完成;否则,未加载完成。Detecting whether the script code corresponding to the scriptAddr attribute of the web page element is loaded is completed in the following way: Detect whether the DOM object collection contained in the window object of the web browser already contains a DOM object whose name is the value of the hashName attribute of the web page element; DOM object, the corresponding script code has been loaded; otherwise, it has not been loaded.
步骤八,判断是否已经创建和当前网页元素对应的script对象,如果是则返回一个空的HTML DOM对象给它的上一级网页布局模板,并返回步骤六;否则,执行步骤九;所述的网页元素对应的script对象是指一种标准的HTML DOM对象,该对象包含了创建网页元素的JavaScript代码,script对象可由Web浏览器提供的DOM接口函数document.createElement()进行创建。Step 8, judge whether the script object corresponding to the current web page element has been created, if so, return an empty HTML DOM object to its upper-level web page layout template, and return to step 6; otherwise, execute step 9; The script object corresponding to the webpage element refers to a standard HTML DOM object, which contains the JavaScript code for creating the webpage element, and the script object can be created by the DOM interface function document.createElement() provided by the web browser.
步骤九,创建和当前网页元素对应的script对象,并将当前网页元素scriptAddr属性的值赋值给该script对象的src属性,将该script对象加入步骤四中创建的全局等待队列中,然后返回一个空的HTML DOM对象给它的上一级网页布局模板,并返回步骤六;所述的script对象加入步骤五中创建的全局等待队列时,以该script对象对应的网页元素的hashName属性值作为全局等待队列的元素索引,以该script对象作为全局等待队列的元素。空的HTML DOM对象是通过Web浏览器的DOM接口函数document.createTextNode()创建了一个空的文本节点。Step 9: Create a script object corresponding to the current web page element, assign the value of the scriptAddr attribute of the current web page element to the src attribute of the script object, add the script object to the global waiting queue created in step 4, and return an empty HTML DOM object to its upper-level webpage layout template, and return to step six; when the script object is added to the global waiting queue created in step five, the hashName attribute value of the webpage element corresponding to the script object is used as the global waiting queue The element index of the queue, the script object is used as the element of the global waiting queue. An empty HTML DOM object is an empty text node created by the DOM interface function document.createTextNode() of the web browser.
步骤十,调用Web浏览器提供的网页渲染引擎接口,渲染步骤六中已创建的网页布局模板及其中包含的HTML DOM对象;所述的Web浏览器提供的网页渲染引擎接口是指Web浏览器的DOM接口函数document.body.appendChild(),该函数被调用时需要把步骤七中已创建的网页布局模板作为参数。Step ten, call the webpage rendering engine interface provided by the web browser, and render the webpage layout template created in step six and the HTML DOM objects contained therein; the webpage rendering engine interface provided by the web browser refers to the webpage rendering engine interface of the web browser The DOM interface function document.body.appendChild() needs to use the web page layout template created in step 7 as a parameter when this function is called.
通过调用document.body.appendChild()实现对已创建的网页布局模板及其中包含的HTML DOM对象进行渲染。By calling document.body.appendChild(), the created web page layout template and the HTML DOM objects contained therein are rendered.
步骤十一,检测所述的全局等待队列是否为空,如果是则网页所有内容加载完成,则退出本方法;否则执行步骤十二;Step 11, detecting whether the global waiting queue is empty, if yes, all the content of the web page is loaded, then exit the method; otherwise, execute step 12;
步骤十二,检测全局等待队列中是否存在已完成加载的script对象,如果有,则从队列中删除该script对象,并返回步骤十一;否则,执行步骤十三;Step 12, detect whether there is a script object that has been loaded in the global waiting queue, if so, delete the script object from the queue, and return to step 11; otherwise, execute step 13;
所述的检测script对象是否加载完成是通过检测全局等待队列中script对象的索引值所对应的DOM对象是否出现在Web浏览器的window对象包含的DOM对象集合中来实现的。The detection of whether the loading of the script object is completed is realized by detecting whether the DOM object corresponding to the index value of the script object in the global waiting queue appears in the DOM object collection contained in the window object of the Web browser.
步骤十三,监听全局等待队列中位于队列首部的script对象的onload事件发生,当该script对象的onload事件发生后,则返回步骤五。所述的监听全局等待队列中位于队列首部的script对象的onload事件发生是指利用JavaScript语言的HTML事件监听机制实现对script对象的onload事件的监听。Step 13, monitor the occurrence of the onload event of the script object at the head of the queue in the global waiting queue, and return to step 5 when the onload event of the script object occurs. The monitoring of the occurrence of the onload event of the script object at the head of the queue in the global waiting queue refers to the monitoring of the onload event of the script object by using the HTML event monitoring mechanism of the JavaScript language.
Claims (3)
- It is 1. a kind of towards the Web page module design of JSON and its Asynchronous loading method, which is characterized in that include the following steps:Step 1 determines the web page element included required for various pieces in page layout format structure and layout structure;Step 2, the page layout structure determined according to step 1 and web page element, use the formal definition webpage of JSON objects Layout templates and corresponding web page element;The page layout template includes page layout container and page layout item This two class component of mesh;The page layout container of definition, page layout entry and web page element are assembled into webpage JSON objects by step 3;Step 4 creates the global waiting list of a HTML DOM object type;Step 5 traverses all objects in the template.childs attributes of JSON objects, judges in ergodic process current Object is page layout template or web page element, then performs step 6 or step 7 according to judging result;When traversal is completed When, turn to step 10;Step 6 if page layout template, then continues to traverse all objects in its childs attribute, and it is every to preserve traversal The HTML DOM objects generated during a object when being completed until traversing, according to all HTML DOM objects of return and are worked as The component attributes of preceding page layout template, the corresponding HTML DOM objects of generation page layout template, are then back to step Five;Step 7 if web page element, then detects whether the corresponding scripted code of web page element scriptAddr attributes adds It carries and completes, if loading is completed, perform the scripted code, create the corresponding HTML DOM objects of the web page element and return to Its upper level page layout template, and return to step six;Otherwise, step 8 is performed;Step 8 judges whether to have created script objects corresponding with current web page element, if it is returns to a sky HTML DOM objects to its upper level page layout template, and return to step six;Otherwise, step 9 is performed;Step 9, creates corresponding with current web page element script objects, and by current web page element scriptAddr attributes Value be assigned to the src attributes of the script objects, which is added in into the global waiting list created in step 4 In, an empty HTML DOM object is then back to its upper level page layout template, and return to step six;Step 10 calls the webpage rendering engine interface of Web browser offer, the page layout mould created in rendering step six Plate and HTML DOM objects wherein included;Step 11 detects whether the global waiting list is empty, and if it is webpage all the elements loading is completed, then is moved back Go out this method;Otherwise step 12 is performed;Step 12 is detected in global waiting list with the presence or absence of the script objects for having completed loading, if so, then from queue Middle deletion script objects, and return to step 11;Otherwise, step 13 is performed;Step 13, the onload events for monitoring the script objects for being located at queue head in global waiting list occur, when this After the onload events of script objects occur, then return to step five.
- 2. as described in claim 1 towards the Web page module design of JSON and its Asynchronous loading method, which is characterized in that institute In the step of stating two, the layout templates of each plate of webpage are defined with page layout entry, and page layout entry must define In page layout container.
- 3. as described in claim 1 towards the Web page module design of JSON and its Asynchronous loading method, which is characterized in that institute In the step of stating three, the rule of assembling is:Page layout entry must be defined in the childs attributes of page layout container, and one It can define multiple page layout entries in a page layout container;Web page element must be defined on the childs of page layout entry In attribute, a web page element corresponds to a page layout entry;It can also be into the childs attributes of page layout entry One step nesting defines page layout container.
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN201710427924.3A CN107357817B (en) | 2017-06-08 | 2017-06-08 | It is a kind of towards the Web page module design of JSON and its Asynchronous loading method |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN201710427924.3A CN107357817B (en) | 2017-06-08 | 2017-06-08 | It is a kind of towards the Web page module design of JSON and its Asynchronous loading method |
Publications (2)
| Publication Number | Publication Date |
|---|---|
| CN107357817A CN107357817A (en) | 2017-11-17 |
| CN107357817B true CN107357817B (en) | 2018-06-26 |
Family
ID=60272375
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN201710427924.3A Active CN107357817B (en) | 2017-06-08 | 2017-06-08 | It is a kind of towards the Web page module design of JSON and its Asynchronous loading method |
Country Status (1)
| Country | Link |
|---|---|
| CN (1) | CN107357817B (en) |
Cited By (1)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US20250238473A1 (en) * | 2024-01-24 | 2025-07-24 | Glitter Company | Method for providing a content including a plurality of digital cuts and electronic device for the same |
Families Citing this family (9)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN108073418A (en) * | 2017-12-29 | 2018-05-25 | 上海全成通信技术有限公司 | A kind of page assembly based on JSON specifications defines method |
| CN109614565B (en) * | 2018-04-04 | 2020-06-23 | 京东数字科技控股有限公司 | Webpage generation method and device |
| CN109725902A (en) * | 2018-12-24 | 2019-05-07 | 广东智合创享营销策划有限公司 | A kind of H5 page animation method and system of complex interaction logic |
| CN109814866B (en) * | 2019-01-31 | 2022-02-08 | 天津字节跳动科技有限公司 | Processing method and device for converting page application into native application |
| CN111813623B (en) * | 2020-06-29 | 2024-02-27 | 北京百度网讯科技有限公司 | Page monitoring method and device, electronic equipment and storage medium |
| CN112434491A (en) * | 2020-11-27 | 2021-03-02 | 杭州信雅达泛泰科技有限公司 | HTML table parsing system and parsing method thereof for JSON |
| CN112818277B (en) * | 2021-01-25 | 2025-02-14 | 京东方科技集团股份有限公司 | Web page generation method, device, storage medium and electronic device |
| CN113326043B (en) * | 2021-05-26 | 2022-05-03 | 上海哔哩哔哩科技有限公司 | Webpage rendering method, webpage manufacturing method and webpage rendering system |
| CN114064001A (en) * | 2021-10-27 | 2022-02-18 | 远光软件股份有限公司 | Web page storage method, device, storage medium and server |
Citations (3)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN104317925A (en) * | 2014-10-31 | 2015-01-28 | 北京思特奇信息技术股份有限公司 | Method and system for efficient front-end development and display |
| CN105049321A (en) * | 2015-07-13 | 2015-11-11 | 陈包容 | Method for data transmission from PC to cellphone |
| CN105095449A (en) * | 2015-07-27 | 2015-11-25 | 福州盈展信息技术有限公司 | Method for converting HTML webpage to mobile terminal page |
-
2017
- 2017-06-08 CN CN201710427924.3A patent/CN107357817B/en active Active
Patent Citations (3)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN104317925A (en) * | 2014-10-31 | 2015-01-28 | 北京思特奇信息技术股份有限公司 | Method and system for efficient front-end development and display |
| CN105049321A (en) * | 2015-07-13 | 2015-11-11 | 陈包容 | Method for data transmission from PC to cellphone |
| CN105095449A (en) * | 2015-07-27 | 2015-11-25 | 福州盈展信息技术有限公司 | Method for converting HTML webpage to mobile terminal page |
Non-Patent Citations (3)
| Title |
|---|
| JSON隔离网站布局和页面实际模块的内容载入;V.Enjoy;《http://developer.51cto.com/art/200904/120685.htm》;20090420;1-2 * |
| JS异步加载的三种方式;前段_小菜;《http://blog.csdn.net/l522703297/article/details/50754695》;20160227;1-8 * |
| 在嵌入式系统中实现AJAX 动态网页技术;胡俊祥;《现代计算机》;20140605(第16期);38-41 * |
Cited By (1)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US20250238473A1 (en) * | 2024-01-24 | 2025-07-24 | Glitter Company | Method for providing a content including a plurality of digital cuts and electronic device for the same |
Also Published As
| Publication number | Publication date |
|---|---|
| CN107357817A (en) | 2017-11-17 |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| CN107357817B (en) | It is a kind of towards the Web page module design of JSON and its Asynchronous loading method | |
| US10726195B2 (en) | Filtered stylesheets | |
| US8799353B2 (en) | Scope-based extensibility for control surfaces | |
| CN103077185B (en) | A kind of method of object-based self-defined extension information | |
| CN111562919A (en) | Method, system and storage medium for generating front-end webpage code based on PSD file | |
| US20120079374A1 (en) | Rendering web page text in a non-native font | |
| CN112100550A (en) | Page construction method and device | |
| US20070136698A1 (en) | Method, system and apparatus for a parser for use in the processing of structured documents | |
| CN108228180A (en) | Real time workshop method and system based on visual interface design | |
| CN111913705B (en) | JavaScript template implementation method based on difference updating algorithm | |
| CN107391153B (en) | Code generation method and device based on Spring and MyBatis framework integration | |
| CN108572819A (en) | Page updating method, device, terminal and computer-readable storage medium | |
| JP6203374B2 (en) | Web page style address integration | |
| CN113126990A (en) | Page development method, device, equipment and storage medium | |
| US11003835B2 (en) | System and method to convert a webpage built on a legacy framework to a webpage compatible with a target framework | |
| US20170111431A1 (en) | Methods for transforming a server side template into a client side template and devices thereof | |
| CN102065114A (en) | Method and device for mobile terminal to access webpage | |
| CN102053994A (en) | Language parser and parsing method using same | |
| US8140575B2 (en) | Apparatus, method, and program product for information processing | |
| US10198408B1 (en) | System and method for converting and importing web site content | |
| CN104050190B (en) | Method and system for processing relation chain data and client | |
| CN101763432A (en) | Method for constructing lightweight webpage dynamic view | |
| CN101617307B (en) | Encoding/decoding apparatus and method | |
| CN114706582B (en) | Icon processing method and device during program operation, electronic device, and storage medium | |
| CN114398138B (en) | Interface generation method, device, computer equipment and storage medium |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| PB01 | Publication | ||
| PB01 | Publication | ||
| SE01 | Entry into force of request for substantive examination | ||
| SE01 | Entry into force of request for substantive examination | ||
| GR01 | Patent grant | ||
| GR01 | Patent grant |