CN114428922A - Page loading method and device, terminal equipment and storage medium - Google Patents

Page loading method and device, terminal equipment and storage medium Download PDF

Info

Publication number
CN114428922A
CN114428922A CN202210081200.9A CN202210081200A CN114428922A CN 114428922 A CN114428922 A CN 114428922A CN 202210081200 A CN202210081200 A CN 202210081200A CN 114428922 A CN114428922 A CN 114428922A
Authority
CN
China
Prior art keywords
resource
static
resources
static resource
reading
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.)
Pending
Application number
CN202210081200.9A
Other languages
Chinese (zh)
Inventor
张亚飞
李可
罗涛
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Industrial and Commercial Bank of China Ltd ICBC
Original Assignee
Industrial and Commercial Bank of China Ltd ICBC
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by Industrial and Commercial Bank of China Ltd ICBC filed Critical Industrial and Commercial Bank of China Ltd ICBC
Priority to CN202210081200.9A priority Critical patent/CN114428922A/en
Publication of CN114428922A publication Critical patent/CN114428922A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/90Details of database functions independent of the retrieved data types
    • G06F16/95Retrieval from the web
    • G06F16/957Browsing optimisation, e.g. caching or content distillation
    • G06F16/9574Browsing optimisation, e.g. caching or content distillation of access to content, e.g. by caching
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/90Details of database functions independent of the retrieved data types
    • G06F16/95Retrieval from the web
    • G06F16/955Retrieval from the web using information identifiers, e.g. uniform resource locators [URL]

Landscapes

  • Engineering & Computer Science (AREA)
  • Databases & Information Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Data Mining & Analysis (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Information Transfer Between Computers (AREA)

Abstract

The embodiment of the application provides a page loading method and device, terminal equipment and a storage medium. The method comprises the following steps: intercepting a static resource request sent by a webpage view WebView when an opening instruction of an application program is received; analyzing a static resource request address URL in the static resource request; reading data streams of the static resources from local resources of the client according to the URL (uniform resource locator) of the static resource request address; creating a plurality of pipe flows and a plurality of asynchronous threads; the pipe flow comprises a pipe input flow and a pipe output flow; writing a data stream to a plurality of pipe output streams using a plurality of asynchronous threads; reading a data stream from a plurality of pipe output streams into a plurality of pipe input streams; the WebView reads a data stream of a pipeline input stream to obtain a static resource; and loading the page of the application program according to the static resource. According to the method, the static resources are loaded through the multiple sub threads simultaneously, and the page loading efficiency is improved.

Description

Page loading method and device, terminal equipment and storage medium
Technical Field
The application relates to the technical field of internet of things, in particular to a page loading method and device, terminal equipment and a storage medium.
Background
Currently, in Android client development, WebView is commonly used for loading an H5 webpage to realize a corresponding function, and the loading process depends on a large number of static resource files such as JavaScript, css and pictures. When the user loads the web page, the client downloads the static resource files, which may prolong the waiting time of the user.
In a possible implementation, a technician packages static resources into an offline front-end resource package that is preset in an application client. When the webpage is loaded, the WebView can read the static resource file required by displaying the current webpage from the local I/O interface of the client, so that the time consumed by downloading the static resource from the network I/O interface is reduced. However, in some WebView versions of the Android system, a single thread is typically used to load static resources. Under the condition of more static resource files and larger volume, a user may still need to spend a certain time waiting for the webpage to be displayed, thereby influencing the use experience of the user.
Disclosure of Invention
The application provides a page loading method, a page loading device, terminal equipment and a storage medium, which are used for solving the problems that WebView uses a single thread to load static resources and loading efficiency is low.
In a first aspect, the present application provides a page loading method, including:
intercepting a static resource request sent by a webpage view WebView when an opening instruction of an application program is received;
optionally, when an opening instruction of an application program is received, before intercepting a static resource request sent by a web view WebView, the method further includes:
acquiring a source static resource from a static resource database of a server;
the source static resources are subjected to hierarchical processing to obtain static resources of public resource categories and static resources of private resource categories; the private resource category and the public resource category are two predefined categories, and the static resource of the public resource category comprises: the technology framework type resources and the cross-service function co-dependent resources; static resources of the private resource category include: each service function depends on resources exclusively or not in common.
Pre-storing static resources of public resource types in a memory, and storing static resources of private resource types in a local resource file; the local resources comprise local resource files and memories; the local resource file is used for storing static resources of a private resource type, and the memory is used for pre-storing the static resources of a public resource type.
Analyzing a static resource request address URL in the static resource request;
reading data streams of the static resources from local resources of the client according to the URL (uniform resource locator) of the static resource request address;
optionally, reading the data stream of the static resource from the local resource of the client according to the static resource request URL includes:
obtaining a resource file path according to the static resource request URL;
and reading the data stream of the static resource from the local resource of the client according to the resource file path.
Optionally, reading a data stream of a static resource from a local resource of a client according to a resource file path includes:
reading static resources from the memory according to the resource file path, if the static resources can be read from the memory, determining the category of the static resources as a public resource category, and converting the static resources into a data stream;
if the static resource can not be read from the memory, reading the static resource from the local resource file according to the resource file path; and if the static resource can be read from the local resource file, determining the type of the static resource as a private resource type, reading the static resource from the local resource file into the memory, reading the static resource from the memory and converting the static resource into a data stream.
Creating a plurality of pipe flows and a plurality of asynchronous threads; the pipe flow comprises a pipe input flow and a pipe output flow;
writing a data stream to a plurality of pipe output streams using a plurality of asynchronous threads;
reading a data stream from a plurality of pipe output streams into a plurality of pipe input streams;
the WebView reads a data stream of a pipeline input stream to obtain a static resource;
and loading the page of the application program according to the static resource.
In a second aspect, the present application provides a page loading apparatus, including:
and the request intercepting module is used for intercepting a static resource request sent by the webpage view WebView when an opening instruction of the application program is received.
And the analysis module is used for analyzing the static resource request address URL in the static resource request.
And the first reading module is used for reading the data stream of the static resource from the local resource of the client according to the static resource request address URL.
Optionally, the first reading module is configured to read a data stream of a static resource from a local resource of a client according to a static resource request address URL, and specifically includes:
and the first acquisition module is used for acquiring the resource file path according to the static resource request URL.
And the first reading submodule is used for reading the data stream of the static resource from the local resource of the client according to the resource file path.
Optionally, the first reading sub-module is configured to read a data stream of a static resource from a local resource of the client according to the resource file path, and specifically includes:
and the memory reading module is used for reading the static resources from the memory according to the resource file path, and if the static resources can be read from the memory, determining the type of the static resources as a public resource type, and converting the static resources into the data stream.
The file reading module is used for reading the static resources from the local resource file according to the resource file path if the static resources cannot be read from the memory; and if the static resource can be read from the local resource file, determining the type of the static resource as a private resource type, reading the static resource from the local resource file into the memory, reading the static resource from the memory and converting the static resource into a data stream.
A pipeline flow module for creating a plurality of pipeline flows and a plurality of asynchronous threads; the pipe flow comprises a pipe input flow and a pipe output flow; writing a data stream to a plurality of pipe output streams using a plurality of asynchronous threads; a data stream is read from a plurality of pipe output streams to a plurality of pipe input streams.
And the second reading module is used for reading the data stream of the pipeline input stream by the WebView to obtain the static resource.
And the page loading module is used for loading the page of the application program according to the static resource.
Optionally, when the request intercepting module receives an opening instruction of an application program, before intercepting a static resource request sent by the web view WebView, the method further includes:
and the second acquisition module is used for acquiring the source static resource from the static resource database of the server.
The classification module is used for performing classification processing on the source static resources to obtain static resources of public resource categories and static resources of private resource categories; the private resource category and the public resource category are two predefined categories, and the static resources of the public resource category include: the technology framework type resources and the cross-service function co-dependent resources; static resources of the private resource category include: each service function depends on the resource exclusively or not in public.
The storage module is used for pre-storing the static resources of the public resource type in a memory and storing the static resources of the private resource type in a local resource file; the local resources comprise local resource files and memories; the local resource file is used for storing static resources of a private resource type, and the memory is used for pre-storing the static resources of a public resource type.
In a third aspect, an embodiment of the present application provides a terminal device, including: a memory and a processor;
the memory is used for storing computer instructions; the processor is configured to execute the memory-stored computer instructions to implement the method of any of the first aspects.
In a fourth aspect, embodiments of the present application provide a computer-readable storage medium on which a computer program is stored, the computer program being executed by a processor to implement the method of any one of the first aspect.
In a fifth aspect, the present application provides a computer program product comprising a computer program that, when executed by a processor, implements the method of any one of the first aspects.
According to the page loading method, the page loading device, the terminal device and the storage medium, after an application interception request shouldnterruptrequest intercepts a static resource request, a static resource data stream is read from a local resource, and depending on the cross-thread transmission characteristic of a pipeline stream (a pipeline output stream PipedOutputStream/a pipeline input stream PipedInputStream), an asynchronous thread writes the data stream into the pipeline output stream, and WebView reads the data stream from the pipeline input stream, so that the static resource file is filled into a network resource sharing WebResourceResponse of the WebView from the local resource file, the multiple static resource loading processes are ensured, the resources can be concurrently loaded through multiple sub-threads to reduce the loading time, and the loading efficiency is improved.
Drawings
Fig. 1 is a schematic view of an application scenario provided in an embodiment of the present application;
fig. 2 is a schematic flowchart of a page loading method according to an embodiment of the present application;
fig. 3 is a schematic flowchart of a page loading method according to another embodiment of the present application;
fig. 4 is a schematic flowchart of a page loading method according to another embodiment of the present application;
fig. 5 is a schematic flowchart of a page loading method according to another embodiment of the present application;
fig. 6 is a schematic structural diagram of a page loading apparatus according to an embodiment of the present application;
fig. 7 is a schematic structural diagram of a page loading terminal device according to an embodiment of the present application.
Detailed Description
Reference will now be made in detail to the exemplary embodiments, examples of which are illustrated in the accompanying drawings. When the following description refers to the accompanying drawings, like numbers in different drawings represent the same or similar elements unless otherwise indicated. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present application. Rather, they are merely examples of apparatus and methods consistent with certain aspects of the present application, as detailed in the appended claims.
The terms referred to in this application are explained first:
web view (WebView): the Android high-performance browser with built-in Webkit kernel is provided with a WebView, the WebView is a control packaged on the basis, and the WebView interprets a webpage view and is used for rendering the function of a Web page and can be regarded as a browser control which can be nested on an interface.
Static resources: the method refers to a file which is dynamically generated by the operation of a non-server, and mainly comprises rendering (html, css and js), pictures (jpeg, gif and png), video files (flv and mpeg) and other files (any download files such as TXT). The static resource is a page which can be displayed directly without looking up a server database and without program processing.
Application intercept request (shouldentreptrequest): the system function callback is used for monitoring the request sent by the WebView and carrying out corresponding processing, and is a system function callback when the webView sends the request. shouldentreptrequest is executed when a new page is about to be opened or redirected (web page automatic redirection or manual click on internal link of web page), and resource loading requests from inside, such as url, js, css and the like, are intercepted.
Resource response object (WebResourceResponse): and responding according to the static resource request, and returning the data corresponding to the static resource request intercepted by the shouldInterceptRequest to the WebView in the form of the class object.
Uniform Resource Locator (URL): URL is a representation used on the Internet WWW service to specify the location of information, specifying Internet protocols such as HTTP or FTP, and is a naming convention that uniquely identifies a particular computer, directory or file location on the Internet.
The page loading method provided by the embodiment of the application can be applied to the application scene schematic diagram shown in fig. 1. As shown in fig. 1, the page loading method provided in the embodiment of the present application may be applied to a client installed with operating systems such as Android, IOS, and Windows. The client is a terminal device held by a user side, and at least one application program can be installed on the client, for example: social applications, communication applications, entertainment applications, payment applications, and the like. And after the user clicks the icon of the application program, the terminal equipment executes the corresponding function of the application program and opens the application program to enter the main page. In this process, after the user clicks on the icon, the interface presented by the client is often a white screen or unresponsive interface-displaying a partial content H5 web page-displaying a full content H5 web page, which means that the user often needs to wait for a certain time while using the application. Taking an application browser as an example, as shown in a in fig. 1, a user clicks a browser icon on a mobile phone interface, and a client responds to the operation. And the mobile phone screen presents an interface shown in b in fig. 1, the interface is a waiting loading interface, and in the process, the WebView of the mobile phone loads the static resources of the browser home page from the local and downloads the dynamic resources from the server. Because the downloading time of the dynamic resource is long, after the static resource is loaded, the interface shown as c in fig. 1 is entered, and the interface displays the web page loaded with the static resource and a part of the dynamic resource. And after all the resources are loaded, entering an interface shown as d in fig. 1, and enabling the user to browse the current webpage based on the mobile phone client.
In possible implementations, the page loading method still has the following problems:
hybrid development technology is commonly used in the current Android client development, namely, WebView is used to load H5 webpage to realize certain functions. The loading process relies on a large number of static resource files such as JavaScript, css, pictures, etc. With the complication of the current web front-end technology development and demand, the volume of static resource files is larger and larger, and the time for downloading static resources is longer and longer when a webpage is loaded. In possible implementation, the static resources are packaged into an offline front-end resource package, and when the client installs the application program installation package, the offline front-end resource package corresponding to the application program is also downloaded to the client, so that the static resource file is preset to the local part of the client. In the using process, when the webpage is loaded, the WebView can directly read the static resource file required by displaying the current webpage from the local I/O interface of the client, so that the time consumed by downloading the static resource from the network I/O interface is reduced. However, in some WebView versions of the Android system, shoulderceptrequest is used to load static resources on a single thread. Under the condition that the static resource files are more and the size is larger, a user may still need to spend a certain time waiting for the webpage to be displayed, and if the shouldntercepttrequest processing time is too long, the WebView interface may be blocked, so that the use experience of the user is influenced.
In order to solve the above problems, the present application provides a page loading method, after a shouldntercepttrequest intercepts a static resource request, a static resource data stream is read from a local resource, depending on the characteristics of cross-thread transmission of a pipeline stream (a pipeline output stream pipe output stream/a pipeline input stream pipe output stream), an asynchronous thread writes the data stream from the pipeline output stream, and a WebView reads the data stream from the pipeline input stream, so that the static resource file is filled into a webresource response of the WebView from the local resource file, and it is ensured that resources can be concurrently loaded through a plurality of sub-threads in the loading process of a plurality of static resources, thereby reducing the loading time and improving the loading efficiency.
The following describes the technical solutions of the present application and how to solve the above technical problems with specific embodiments. The following several specific embodiments may be combined with each other, and details of the same or similar concepts or processes may not be repeated in some embodiments. Embodiments of the present application will be described below with reference to the accompanying drawings.
Fig. 2 is a schematic flowchart of a static data loading method according to an embodiment of the present application. Referring to fig. 2, the method may include:
s201, intercepting a static resource request sent by a webpage view WebView when an opening instruction of an application program is received.
The starting instruction is used for controlling and indicating the client to start the application program. Optionally, the user clicks an icon of an existing application program of the client, the client operating system responds to the operation, the application program is started according to the received opening instruction of the application program, and at this time, it can be detected that the application program is in an open state. Alternatively, the user may open other applications based on the application currently already in the open state. For example: the user carries out the action of charging on a charging page of the game application program, the client can start the application program with the payment function from the game application program, the client interface jumps from the game charging interface to the payment interface, and at the moment, the payment application program can be detected to be in the starting state.
And when receiving a starting instruction of the application program and responding to the starting instruction, the WebView of the client initiates a static resource request. When accessing the H5 page, the client sends a web page request requesting to obtain static and dynamic resources for rendering the H5 page. The webpage request requests to load the static resources is a static resource request. The static resource request is for requesting a static resource to load the H5 page content of the application into the local resource of the client. Static resources may include: JavaScript files, css files, pictures, and the like. When WebView initiates a static resource request, intercepting the static resource request by an application interception request shouldInterceptRequest method of WebView.
Illustratively, Webview adds an event listening object (WebViewClient) to rewrite an application interception request shouldntercepterrequest, which intercepts a static resource request.
S202, analyzing the static resource request address URL in the static resource request.
The static resource request comprises a static resource request address URL, and the WebView analyzes the intercepted static resource request to obtain the URL. The static resource request address URL is a URL address which needs to be accessed when the static resource is loaded on the page.
And S203, reading the data stream of the static resource from the local resource of the client according to the URL.
The URL comprises information capable of finding the corresponding static resource, and the static resource information can be the file name of the static resource in a static resource list when the static resource is preset to the client; or a character string formed by static resource conversion processing, which is not limited in this application.
Optionally, the resource file path is obtained according to the static resource request URL.
After the client analyzes the URL of the static resource request, the client addresses the static resource in the local resource and determines a resource file path. Illustratively, the URL addresses the local resource according to a matching rule, where the matching rule may be a file name of the static resource, a character string after conversion processing of the static resource, or addressing according to other matching rules. The client can determine the path of the only static resource matched by the URL through the internal logic and convert the path into the resource file path of the client.
After the request, getUrl resolves the static resource request address URL, the address of the static resource in the local resource can be searched according to the output directory of the FileLoader, that is, the local resource file path can be obtained according to the URL. The client may address the static resource into the local resource based on the local resource file path.
Illustratively, the implementation code is as follows:
Figure BDA0003485977970000071
optionally, the data stream of the static resource is read from the local resource of the client according to the resource file path.
Illustratively, the static resource is read from the local resource based on an input stream (InputStream) in the Java IO, and the static resource is converted into a data stream. The InputStream is connected with a data source for reading byte data, and the data source comprises files, network connection, pipelines and the like.
S204, creating a plurality of pipeline flows and a plurality of asynchronous threads; the pipe flow comprises a pipe input flow and a pipe output flow.
A pipe stream is a Java stream used for information transfer between multiple threads, and has the characteristic of cross-thread transfer. The pipe streams include a pipe output stream (pipe outputstream) and a pipe input stream (pipe inputstream). Asynchronous threads are used for reading and writing of data streams between local resources and the pipe and between the pipe and WebView.
Before formally using the pipe flow, java creates multiple pipe flows and multiple asynchronous threads. The multiple pipeline streams and the corresponding asynchronous threads can realize the function of multithreading concurrent loading of static resources.
Illustratively, the implementation code is as follows:
Figure BDA0003485977970000081
the pipeline input stream and the pipeline output stream are respectively connected with different threads. Illustratively, as shown in FIG. 3, multiple child threads concurrently load static resources. The pipeline output stream is connected with a plurality of asynchronous thread A, thread C and the like, the pipeline input stream is connected with thread B and thread D, and after the pipeline input stream is associated with the pipeline output stream, the data stream can be transmitted from the thread A and transmitted to the thread B in a crossing manner; the data stream is transmitted by thread C across to thread D.
In the embodiment of the present application, a method of using a constructor to correlate a pipe input stream with a pipe output stream is exemplarily given, and it is to be understood that the method of connecting the pipe input stream and the pipe output stream together is not exclusive, and the present application is not limited thereto.
And S205, writing the data stream into a plurality of pipeline output streams by using a plurality of asynchronous threads.
A pipe output stream corresponds to a pipe input stream to form a pair of pipe streams. The plurality of asynchronous threads write the data streams to the plurality of pipe output streams. Illustratively, as shown in fig. 3, thread a, thread C, etc. read the data stream of static resources from the local resources, and the data stream is transmitted to the pipe output stream through thread a, thread C, etc.
S206, reading the data stream from the plurality of pipeline output streams to a plurality of pipeline input streams.
After the pipe input stream is associated with the pipe output stream, the pipe input stream can read the static resource data stream written by the pipe output stream.
S207, reading the data stream of the pipeline input stream by the WebView to obtain the static resource.
WebView reads the data stream of the pipeline input stream by using the WebResourceResponse shared by the network resources to obtain the static resources.
WebView creates Response using the pipe input stream. After the Response returns, WebView can read the data stream of the pipeline input stream by using WebResourceResponse, so that static resources are obtained.
Illustratively, the implementation code is as follows:
Figure BDA0003485977970000091
and S208, loading the page of the application program according to the static resource.
And the client renders the H5 page according to the static resource, and displays the rendered H5 page of the static resource on a display interface of the client.
According to the page loading method provided by the embodiment of the application, the static resource data stream is filled into the WebResourceResponse of WebView in a pipeline stream mode by depending on the pipeline output stream and the pipeline input stream packaged by Java, so that the concurrent loading of resources by multiple threads is realized, and the page loading efficiency is improved.
Fig. 4 is a schematic flowchart of a page loading method according to an embodiment of the present application. Referring to fig. 4, before intercepting a static resource request sent by a web view WebView when receiving a start instruction of an application program, the method further includes:
s301, obtaining the source static resource in the static resource database of the server.
For example, when the client starts the application, the client detects the update state of the application. And if the newly released version exists in the application program, the client acquires the source static resource from the static resource database of the server, wherein the source static resource is the updated static resource.
Illustratively, if the application does not have an updated version, then the static resources in the current local resources are used. When the client downloads the application program for the first time, the application program installation package is downloaded from the server, the application program installation package comprises source static resources, and the installation package can be an Android installation package (apk) file, an iPhone installation package (ipa) file or a Windows Phone installation package (xap) file. When the client side installs the application program, the source static resource is preset to the local resource of the client side. The storage position of the source static resource in the local resource can be set by user customization.
S302, the static resources of the public resource category and the static resources of the private resource category are obtained through grading processing of the source static resources.
Optionally, in order to load resources more reasonably and efficiently, the source static resources are equally divided into static resources (public resources) of the public resource type and static resources (private resources) of the private resource type according to the service function and the application frequency; the private resource category and the public resource category are two predefined categories.
The common resources include: technical framework class resources and co-dependent resources across service functions. The technical framework type resource is a static resource of a front-end framework type. Illustratively, the jQuery is a fast and compact JavaScript framework, and js static resources at the front end all depend on a jQuery code base. Js type files belong to technical framework type resources. Each application program is provided with a plurality of service functions, and correspondingly, the realization of each function corresponds to one H5 page. At the time of H5 page load, WebView issues a static resource request corresponding to the current H5 page. Static requests for loading different pages may contain co-dependent static resources, and the part of static resources is defined as co-dependent resources of cross-service functions.
The private resources include: each service function depends on the resource exclusively or not in public. Accordingly, static resources that do not satisfy the public resource type are set as private resources, i.e., static resources that are unique to or not publicly dependent on each page when multiple pages are loaded.
For example, after the client acquires the source static resource, the web front end may analyze the static resource on which the web page corresponding to each function in the application program depends. Judging whether the static resources are resources or technical framework resources which are depended on together when a plurality of pages are loaded, and if so, determining the static resources as public resources; otherwise, the resource is determined to be a private resource.
S303, pre-storing the static resources of the public resource type in a memory, and storing the static resources of the private resource type in a local resource file.
The local resources comprise local resource files and memories; the local resource file is used for storing static resources of a private resource type, and the memory is used for pre-storing the static resources of a public resource type.
Optionally, when the static resource type is a public resource type, pre-reading the public resource into the memory; and when the static resource category is the private resource category, storing the private resource into the local resource file.
According to the page loading method provided by the embodiment of the application, static resources are subjected to hierarchical processing, the static resources are divided into public resources and private resources, and the public resources are pre-read into a memory in advance. When the page is loaded, the public resource with higher application frequency can be directly read from the memory, and the private resource keeps a file reading mode, so that the reading efficiency of the static resource is improved while the memory is prevented from occupying too high.
Exemplarily, fig. 5 is a schematic flowchart of a page loading method provided in an embodiment of the present application. As shown in fig. 5, reading a data stream of a static resource from a local resource of a client according to a resource file path includes:
s501, reading static resources from the memory according to the resource file path, if the static resources can be read from the memory, determining that the static resources are public resources, and converting the static resources into data streams.
In a possible implementation, the H5 webpage loads static resources in a file reading manner, and the efficiency of file reading is much lower than that of memory reading. If all static resources are pre-read into the memory, the memory occupation may be too high, which may cause the problem of memory overflow. Public resources are pre-read into the memory, so that the resources can be loaded from the memory more quickly, and private resources keep a file reading mode, thereby preventing the memory from occupying too high.
Optionally, the addressing priority is set according to the resource file path. And preferentially reading the static resources from the memory, and if the static resources can be addressed in the memory, indicating that the static resources are public resources. And directly reading the byte array of the common resource from the memory and converting the byte array into a data stream.
Illustratively, as shown in a of fig. 5, the data stream of the common resource is read from the memory and written to the pipe output stream by thread a. After the pipe input stream is associated with the pipe output stream, the pipe input stream reads the data stream in the pipe output stream. WebView reads the data stream of the pipe input stream into WebResourceResponse.
S502, if the static resource can not be read from the memory, reading the static resource from the local resource file according to the resource file path; and if the static resource can be read from the local resource file, determining that the static resource type is a private resource type, reading the static resource from the local resource file into the memory, reading the static resource from the memory and converting the static resource into a data stream.
Optionally, if the static resource is not addressed in the memory, the static resource is addressed in the local resource file according to the resource file path. And if the static resource can be addressable from the local resource file, the static resource is a private resource. Setting a byte array as a cached memory, reading static resources from a local resource file into the memory, reading the byte array of the public resources from the memory, and converting the byte array into a data stream. The pipeline output stream can read the data stream to realize the concurrent loading of the resources by the multiple sub threads.
Illustratively, as shown in b of FIG. 5, the data stream of the private resource is read from the local resource file and written to the pipe output stream by thread C. After the pipe input stream is associated with the pipe output stream, the pipe input stream reads the data stream in the pipe output stream. WebView reads the data stream of the pipe input stream into WebResourceResponse.
Illustratively, the implementation code is as follows:
Figure BDA0003485977970000111
Figure BDA0003485977970000121
according to the page loading method provided by the embodiment of the application, the public resources are pre-read into the memory, so that the resources are loaded from the memory more quickly, the private resources maintain a file reading mode, and the memory occupation is prevented from being too high.
Fig. 6 is a schematic structural diagram of a data processing apparatus according to an embodiment of the present application. As shown in fig. 6, the data processing apparatus 60 provided in the present embodiment may include:
the request intercepting module 601 is configured to intercept a static resource request sent by the web view WebView when an opening instruction of an application program is received.
The parsing module 602 is configured to parse the static resource request address URL in the static resource request.
The first reading module 603 is configured to read a data stream of the static resource from the local resource of the client according to the static resource request address URL.
Optionally, the first reading module 603 is configured to read a data stream of a static resource from a local resource of a client according to a static resource request address URL, and specifically includes:
and the first acquisition module is used for acquiring the resource file path according to the static resource request URL.
And the first reading submodule is used for reading the data stream of the static resource from the local resource of the client according to the resource file path.
Optionally, the first reading sub-module is configured to read a data stream of a static resource from a local resource of the client according to the resource file path, and specifically includes:
and the memory reading module is used for reading the static resources from the memory according to the resource file path, determining the static resource type as a public resource type if the static resources can be read from the memory, and converting the static resources into the data stream.
The file reading module is used for reading the static resources from the local resource file according to the resource file path if the static resources cannot be read from the memory; and if the static resource can be read from the local resource file, determining that the static resource type is a private resource type, reading the static resource from the local resource file into the memory, reading the static resource from the memory and converting the static resource into a data stream.
A pipe flow module 604 for creating a plurality of pipe flows and a plurality of asynchronous threads; the pipe flow comprises a pipe input flow and a pipe output flow; writing a data stream to a plurality of pipe output streams using a plurality of asynchronous threads; a data stream is read from a plurality of pipe output streams to a plurality of pipe input streams.
And the second reading module 605 is configured to read, by the WebView, a data stream of the pipe input stream to obtain the static resource.
And a page loading module 606, configured to load a page of the application program according to the static resource.
Optionally, when the request intercepting module 601 receives a start instruction of an application program, before intercepting a static resource request sent by a web view WebView, the method further includes:
and the second acquisition module is used for acquiring the source static resource from the static resource database of the server.
The classification module is used for performing classification processing on the source static resources to obtain static resources of public resource categories and static resources of private resource categories; the private resource category and the public resource category are two predefined categories, and the static resources of the public resource category include: the technology framework type resources and the cross-service function co-dependent resources; static resources of the private resource category include: each service function depends on the resource exclusively or not in public.
The storage module is used for pre-storing the static resources of the public resource type in a memory and storing the static resources of the private resource type in a local resource file; the local resources comprise local resource files and memories; the local resource file is used for storing static resources of a private resource type, and the memory is used for pre-storing the static resources of a public resource type.
The data processing apparatus according to the embodiment of the present application may be configured to implement the technical solution of the data processing method embodiment, and the implementation principle and the technical effect are similar, which are not described herein again.
Fig. 7 is a schematic structural diagram of a data processing terminal device according to an embodiment of the present application. As shown in fig. 7, the data processing terminal device 70 provided in the present embodiment may include:
a processor 701; and
a memory 702 for storing executable instructions of the terminal device;
the processor is configured to execute the technical solution of the above-described data processing method embodiment by executing the executable instructions, and the implementation principle and technical effect are similar, which are not described herein again.
The embodiment of the present application further provides a computer-readable storage medium, where a computer program is stored, and when the computer program is executed by a processor, the technical solution of the embodiment of the data processing method is implemented, and the implementation principle and the technical effect are similar, and are not described herein again.
In an embodiment of the present application, a computer program product is further provided, where the computer program is executed by a processor to implement the technical solution of the data processing method embodiment, and the implementation principle and the technical effect are similar, and are not described herein again.
In the above Specific implementation of the terminal device or the server, it should be understood that the Processor may be a Central Processing Unit (CPU), other general purpose processors, a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), etc. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like. The steps of the method disclosed in connection with the embodiments of the present application may be directly implemented by a hardware processor, or implemented by a combination of hardware and software modules in a processor.
Those skilled in the art will appreciate that all or a portion of the steps of any of the above-described method embodiments may be performed by hardware associated with program instructions. The foregoing program may be stored in a computer-readable storage medium, and when executed, performs all or a portion of the steps of the above-described method embodiments.
The technical scheme of the application can be stored in a computer readable storage medium if the technical scheme is realized in a software form and is sold or used as a product. Based on this understanding, all or part of the technical solutions of the present application may be embodied in the form of a software product stored in a storage medium, including a computer program or several instructions. The computer software product enables a computer device (which may be a personal computer, a server, a network device, or a similar electronic device) to perform all or part of the steps of the method according to one embodiment of the present application. The storage medium may be various media capable of storing program codes, such as a usb disk, a removable hard disk, a ROM, a Random Access Memory (RAM), a magnetic disk, or an optical disk.
Finally, it should be noted that: the above embodiments are only used for illustrating the technical solutions of the present application, and not for limiting the same; although the present application has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art will understand that: the technical solutions described in the foregoing embodiments may still be modified, or some or all of the technical features may be equivalently replaced; and the modifications or the substitutions do not make the essence of the corresponding technical solutions depart from the scope of the technical solutions of the embodiments of the present application.
Other embodiments of the present application will be apparent to those skilled in the art from consideration of the specification and practice of the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of the invention following, in general, the principles of the application and including such departures from the present disclosure as come within known or customary practice within the art to which the invention pertains. It is intended that the specification and examples be considered as exemplary only, with a true scope and spirit of the application being indicated by the following claims.
It will be understood that the present application is not limited to the precise arrangements that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the application is limited only by the appended claims.

Claims (11)

1. A page loading method is applied to a client side, and comprises the following steps:
intercepting a static resource request sent by a webpage view WebView when an opening instruction of an application program is received;
analyzing a static resource request address URL in the static resource request;
reading data flow of the static resource from the local resource of the client according to the static resource request address URL;
creating a plurality of pipe flows and a plurality of asynchronous threads; the pipe flow comprises a pipe input flow and a pipe output flow;
writing the data stream to a plurality of the pipe output streams using a plurality of the asynchronous threads;
reading a data stream from a plurality of said pipe output streams into a plurality of said pipe input streams;
the WebView reads the data stream of the pipeline input stream to obtain the static resource;
and loading the page of the application program according to the static resource.
2. The method of claim 1, wherein the local resources comprise local resource files and memory; the local resource file is used for storing static resources of a private resource type, and the memory is used for pre-storing static resources of a public resource type; the private resource category and the public resource category are two predefined categories, and the static resource of the public resource category includes: the technology framework type resources and the cross-service function co-dependent resources; the static resources of the private resource category include: each service function depends on the resource exclusively or not in public.
3. The method of claim 2, wherein reading the data stream of the static resource from the local resource of the client according to the static resource request URL comprises:
obtaining a resource file path according to the static resource request URL;
and reading the data stream of the static resource from the local resource of the client according to the resource file path.
4. The method according to claim 3, wherein the reading the data stream of the static resource from the local resource of the client according to the resource file path comprises:
reading the static resource from the memory according to the resource file path, if the static resource can be read from the memory, determining the type of the static resource as the public resource type, and converting the static resource into the data stream;
if the static resource can not be read from the memory, reading the static resource to the local resource file according to the resource file path; if the static resource can be read in the local resource file, determining that the type of the static resource is the private resource type, reading the static resource from the local resource file into the memory, reading the static resource from the memory and converting the static resource into the data stream.
5. The method according to claim 2, wherein before intercepting the static resource request sent by the WebView upon receiving the opening instruction of the application program, the method further comprises:
acquiring a source static resource from a static resource database of a server;
the static resources of the public resource category and the static resources of the private resource category are obtained by carrying out grading processing on the source static resources;
and pre-storing the static resources of the public resource type in the memory, and storing the static resources of the private resource type in the local resource file.
6. The method according to claim 1 or 2, wherein intercepting the static resource request sent by the web page view WebView when receiving the opening instruction of the application program comprises:
and intercepting the static resource request sent by the WebView by using an application interception request shouldInterceptRequest when the opening instruction of the application program is received.
7. The method of claim 1 or 2, wherein the WebView reads the data stream of the pipe input stream to obtain the static resource, and comprises:
and the WebView reads the data stream of the pipeline input stream by using a WebResourceResponse shared by network resources to obtain the static resources.
8. A page loading apparatus, applied to a client, the apparatus comprising:
the request intercepting module is used for intercepting a static resource request sent by the webpage view WebView when an opening instruction of an application program is received;
the analysis module is used for analyzing a static resource request address URL in the static resource request;
the first reading module is used for reading data streams of the static resources from the local resources of the client according to the static resource request address URL;
a pipeline flow module for creating a plurality of pipeline flows and a plurality of asynchronous threads; the pipe flow comprises a pipe input flow and a pipe output flow; writing the data stream to a plurality of the pipe output streams using a plurality of the asynchronous threads; reading a data stream from a plurality of said pipe output streams into a plurality of said pipe input streams;
a second reading module, configured to read, by the WebView, the data stream of the pipe input stream to obtain the static resource;
and the page loading module is used for loading the page of the application program according to the static resource.
9. A terminal device, comprising: a memory and a processor;
the memory is to store computer instructions; the processor is configured to execute the computer instructions stored by the memory to implement the method of any of claims 1-7.
10. A computer-readable storage medium, having stored thereon a computer program for execution by a processor to perform the method of any one of claims 1-7.
11. A computer program product, characterized in that it comprises a computer program which, when being executed by a processor, carries out the method of any one of claims 1-7.
CN202210081200.9A 2022-01-24 2022-01-24 Page loading method and device, terminal equipment and storage medium Pending CN114428922A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210081200.9A CN114428922A (en) 2022-01-24 2022-01-24 Page loading method and device, terminal equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210081200.9A CN114428922A (en) 2022-01-24 2022-01-24 Page loading method and device, terminal equipment and storage medium

Publications (1)

Publication Number Publication Date
CN114428922A true CN114428922A (en) 2022-05-03

Family

ID=81312577

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210081200.9A Pending CN114428922A (en) 2022-01-24 2022-01-24 Page loading method and device, terminal equipment and storage medium

Country Status (1)

Country Link
CN (1) CN114428922A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117407091A (en) * 2023-12-12 2024-01-16 中核武汉核电运行技术股份有限公司 Rapid WEB picture loading method and system based on file localization deployment

Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104573066A (en) * 2015-01-26 2015-04-29 中国工商银行股份有限公司 Page reusing method and page reusing device
CN106095506A (en) * 2016-06-14 2016-11-09 乐视控股(北京)有限公司 A kind of page loading method and device
CN106933865A (en) * 2015-12-31 2017-07-07 北京五八信息技术有限公司 The resource loading method and device of mobile applications web application
CN108520031A (en) * 2018-03-27 2018-09-11 广东能龙教育股份有限公司 Method for increasing webpage loading speed
CN110020326A (en) * 2018-09-07 2019-07-16 天翼电子商务有限公司 A method of promoting Webview opening speed
US20200057658A1 (en) * 2017-03-08 2020-02-20 Alibaba Group Holding Limited Method and system for loading resources
CN111159605A (en) * 2019-12-31 2020-05-15 杭州云缔盟科技有限公司 Method for solving problem of slow page loading after intercepting and forwarding request of Android Webview
CN112988284A (en) * 2021-05-13 2021-06-18 太平金融科技服务(上海)有限公司 Application program starting method and device, computer equipment and storage medium

Patent Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104573066A (en) * 2015-01-26 2015-04-29 中国工商银行股份有限公司 Page reusing method and page reusing device
CN106933865A (en) * 2015-12-31 2017-07-07 北京五八信息技术有限公司 The resource loading method and device of mobile applications web application
CN106095506A (en) * 2016-06-14 2016-11-09 乐视控股(北京)有限公司 A kind of page loading method and device
US20200057658A1 (en) * 2017-03-08 2020-02-20 Alibaba Group Holding Limited Method and system for loading resources
CN108520031A (en) * 2018-03-27 2018-09-11 广东能龙教育股份有限公司 Method for increasing webpage loading speed
CN110020326A (en) * 2018-09-07 2019-07-16 天翼电子商务有限公司 A method of promoting Webview opening speed
CN111159605A (en) * 2019-12-31 2020-05-15 杭州云缔盟科技有限公司 Method for solving problem of slow page loading after intercepting and forwarding request of Android Webview
CN112988284A (en) * 2021-05-13 2021-06-18 太平金融科技服务(上海)有限公司 Application program starting method and device, computer equipment and storage medium

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
铂金小鸟: "Android WebView shouldInterceptRequest 异步加载", 《HTTPS://MY.OSCHINA.NET/FANTS/BLOG/389648》 *

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN117407091A (en) * 2023-12-12 2024-01-16 中核武汉核电运行技术股份有限公司 Rapid WEB picture loading method and system based on file localization deployment
CN117407091B (en) * 2023-12-12 2024-03-19 中核武汉核电运行技术股份有限公司 Rapid WEB picture loading method and system based on file localization deployment

Similar Documents

Publication Publication Date Title
US11647096B2 (en) Method and apparatus for automatically optimizing the loading of images in a cloud-based proxy service
CN110120917B (en) Routing method and device based on content
US9565265B2 (en) Method and apparatus for automatically optimizing the loading of images in a cloud-based proxy service
WO2020199751A1 (en) Method and apparatus for loading page picture, and electronic device
CN111666497B (en) Application program loading method and device, electronic equipment and readable storage medium
CN112269959B (en) Control method and device for display content, readable medium and electronic equipment
US11032683B2 (en) Method and apparatus for publishing cloud resource
US9906626B2 (en) Resource demand-based network page generation
CA2745981C (en) A computer-implemented method, a computer program product and an embedded system for increasing the speed of data retrieval by a client on the embedded system
CN111651703A (en) Page jump method and device, electronic equipment and readable storage medium
KR20120016333A (en) Pre-caching method for web application and device using the same
CN114428922A (en) Page loading method and device, terminal equipment and storage medium
US9270727B1 (en) Facilitating access to data in network page generation code
EP3125541A1 (en) Data acquisition and interaction method, set top box, server and multimedia system
CN116561013B (en) Testing method and device based on target service framework, electronic equipment and medium
CN103793459B (en) Webpage opening method and device
CN110851194A (en) Method and device for acquiring code for realizing new interface
US11379653B2 (en) Rendering method for on-demand loading of PDF file on network
US10990750B2 (en) Dynamically bundling web page resources
US20150248347A1 (en) Content providing apparatus and method, and computer program product
CN112835671A (en) Application page scene switching method, device and equipment
CN112256992A (en) Native rendering method and device for information stream fusing multi-link addresses
CN112596838B (en) Method, device, equipment and storage medium for displaying universal Web page
CN113630434A (en) Processing method for client access request and server
US9363321B2 (en) Analytics based scoping of HTML5 web storage attributes

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
RJ01 Rejection of invention patent application after publication

Application publication date: 20220503

RJ01 Rejection of invention patent application after publication