Network resource loading method, system, electronic device and storage medium
By identifying the client's access permission identification information on the server side and automatically adjusting the CDN resource loading path, the problem of low loading efficiency of network resources in a proprietary cloud environment is solved, and efficient and intelligent resource loading is achieved.
Patent Information
- Application Number
- CN202411884861.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-19
- Publication Date
- 2025-05-13
- Estimated Expiration
- 2044-12-19
AI Technical Summary
In proprietary cloud environments, the limitations of CDN loading strategies lead to inefficient loading network resources and the lack of effective solutions in the prior art.
By identifying the identification information in the client's page access request on the server side, it is automatically determined whether the client has the permission to access the CDN resource, and returns the appropriate page version accordingly, thereby achieving efficient and intelligent loading of resources.
Without manual intervention, the loading efficiency of network resources is improved, the problem of low loading efficiency of network resources is solved, and good adaptability and performance are maintained in public and proprietary cloud environments.
Smart Images

Figure CN119342052B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer network technology, and in particular to a method, system, electronic device and storage medium for loading network resources. Background Art
[0002] At present, in the current Internet technology system, Content Delivery Network (CDN) is widely used in public cloud products to adjust the loading efficiency of network resources (also called CDN resources, such as front-end resources). CDN deploys server nodes dispersedly around the world, and can redirect requests to the nearest node based on the proximity of the user's geographical location, thereby significantly reducing the delay in resource loading and improving user experience. The above method is effective in a public cloud environment (cloud computing services provided through a public network), especially in large-scale, cross-regional user access scenarios, where CDN can effectively share the traffic pressure of the main server and improve the loading speed and stability of resources.
[0003] However, when such public cloud products need to be deployed in private cloud products, the limitations of CDN loading strategies become apparent. Since the private network that provides cloud computing services corresponding to the private cloud environment is a communication network specially established for a specific organization or entity, its network rules and access policies are often different from those of the public network (public network), and are more focused on security and privacy. This means that direct access to the public network CDN may not be allowed in the private network, or the access speed of the public network CDN is far less efficient than the resource loading efficiency within the private network, which directly leads to the problem of CDN resource loading failure when the website or software is deployed in the private network.
[0004] In related technologies, in order to cope with the challenge of deploying CDN to a private network, manual intervention is often required, such as switching the reference of CDN resources to the resource server in the private network by modifying the code or configuration. This manual switching method is not only time-consuming and labor-intensive, but also increases the complexity of deployment and maintenance. Therefore, there is still a technical problem of low loading efficiency of network resources.
[0005] To address the above-mentioned problems, no effective solution has been proposed yet. Summary of the invention
[0006] The embodiments of the present application provide a method, system, electronic device and storage medium for loading network resources, so as to at least solve the technical problem of low loading efficiency of network resources.
[0007] According to one aspect of an embodiment of the present application, a method for loading a network resource is provided. The method can be applied to a server, and includes: obtaining a page access request from a client, wherein the page access request is used to request an access page from a server; in response to the page access request, identifying identification information from the page access request, wherein the identification information is used to indicate the client's authority to access a content distribution network; determining at least one target page matching the identification information, and a network resource matching the identification information, wherein the page type of the target page corresponds to the authority corresponding to the identification information, and the source of the network resource corresponds to the authority corresponding to the identification information; returning the target page to the client, and loading the network resource to the target page.
[0008] According to another aspect of the embodiment of the present application, another method for loading network resources is provided. The method is applied to a client and may include: sending a page access request to a server, wherein the page access request is used to request an access page from the server; loading at least one target page returned by the server in response to the page access request, and loading the corresponding network resource on the target page, wherein the target page matches the identification information in the page access request, and the loaded network resource matches the identification information, the identification information is used to indicate the client's permission to access the content distribution network, the page type of the target page corresponds to the permission corresponding to the identification information, and the source of the network resource corresponds to the permission corresponding to the identification information.
[0009] According to another aspect of the embodiment of the present application, another method for loading network resources is provided. The method is applied to a server, a plug-in is installed on the server, and the server is used to call the plug-in to execute the following method: obtain a page access request from a client, wherein the page access request is used to request an access page from the server; in response to the page access request, identify identification information from the page access request, wherein the identification information is used to indicate the client's authority to access a content distribution network; determine at least one target page matching the identification information, and a network resource matching the identification information, wherein the page type of the target page corresponds to the authority corresponding to the identification information, and the source of the network resource corresponds to the authority corresponding to the identification information; return the target page to the client, and load the network resource to the target page.
[0010] According to another aspect of the embodiment of the present application, a network resource loading system is provided. The system is deployed in a public network or a proprietary network, and the system may include: a client and a server, wherein the client is used to send a page access request to the server, wherein the page access request is used to request the server to access a page; the server is used to respond to the page access request and identify identification information from the page access request, wherein the identification information is used to indicate the client's authority to access a content distribution network; determine at least one target page matching the identification information, and a network resource matching the identification information, wherein the page type of the target page corresponds to the authority corresponding to the identification information, and the source of the network resource corresponds to the authority corresponding to the identification information; wherein the client is used to load the target page returned by the server, and load the network resource on the target page.
[0011] According to another aspect of the embodiment of the present application, an electronic device is further provided. The electronic device may include a memory and a processor: the memory is used to store computer executable instructions, and the processor is used to execute the computer executable instructions. When the computer executable instructions are executed by the processor, the network resource loading method of the embodiment of the present application is implemented.
[0012] According to another aspect of an embodiment of the present application, a processor is further provided. The processor is used to run a program, wherein the method for loading network resources of the embodiment of the present application is executed when the program is running.
[0013] According to another aspect of the embodiment of the present application, a computer-readable storage medium is provided, which includes a stored program, wherein when the program is executed, the device where the storage medium is located is controlled to execute the network resource loading method of the embodiment of the present application.
[0014] According to another aspect of the embodiment of the present application, a computer program product is also provided. The computer program product includes a computer program, and when the computer program is executed by a processor, the network resource loading method of the embodiment of the present application is implemented.
[0015] In an embodiment of the present application, if it is necessary to load network resources, it is possible to monitor in real time whether the client has a request to access a certain page (that is, the front-end page), that is, a page access request. If a page access request is monitored, it is possible to analyze whether the client has identification information corresponding to the authority to access the CDN. If there is no such identification information in the access request, the network resources in the page cannot be loaded. On the contrary, at least one accessible target page matching the authority in the identification information can be determined. And the target page can be returned to the corresponding client, and the network resources on the target page can be loaded on the client. In other words, in an embodiment of the present application, a front-end resource adaptive loading method is proposed, the core of which is to automatically determine whether the client has the authority to access the CDN resource according to the identification information contained in the page access request, and return the appropriate page version accordingly, so as to achieve efficient and intelligent loading of resources without manual intervention when the CDN is deployed to the private network. The above method can maintain good adaptability and performance in both public cloud and private cloud environments, thereby achieving the technical effect of improving the loading efficiency of network resources and solving the technical problem of low loading efficiency of network resources.
[0016] It is easy to notice that the above general description and the following detailed description are only for the purpose of exemplifying and explaining the present application, and do not constitute a limitation of the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:
[0018] Figure 1 is a schematic diagram of an application scenario of a method for loading network resources according to an embodiment of the present application;
[0019] Figure 2 is a flow chart of a method for loading network resources according to an embodiment of the present application;
[0020] Figure 3 is a flowchart of another method for loading network resources according to an embodiment of the present application;
[0021] Figure 4 is a flowchart of another method for loading network resources according to an embodiment of the present application
[0022] Figure 5 is a flow chart of a network resource loading system according to an embodiment of the present application;
[0023] Figure 6It is a schematic diagram of a front-end resource loading method in the related art;
[0024] Figure 7 It is a flow chart of a method for adaptively loading front-end resources in a proprietary network according to an embodiment of the present application;
[0025] Figure 8 It is a schematic diagram of the loading logic of the front-end resources when a modified page is running in a browser according to an embodiment of the present application;
[0026] Fig. 9 It is a schematic diagram of the loading logic of the front-end resources when a page using the resources of this website is run in a browser according to an embodiment of the present application;
[0027] Fig.10 is a schematic diagram of an interceptor for newly adding page access according to an embodiment of the present application;
[0028] Fig.11 It is a flow chart of a method for adaptively loading front-end resources in a proprietary network according to an automated implementation of an embodiment of the present application;
[0029] Fig.12 is a schematic diagram of a network resource loading device according to an embodiment of the present application;
[0030] Fig.13 is a schematic diagram of another network resource loading device according to an embodiment of the present application;
[0031] Fig.14 is a schematic diagram of another network resource loading device according to an embodiment of the present application;
[0032] Fig.15 is a structural block diagram of a computer terminal according to an embodiment of the present application;
[0033] Fig.16 is a block diagram of an electronic device for a method for loading network resources according to an embodiment of the present application;
[0034] Fig.17 It is a hardware structure block diagram of a computer terminal (or mobile device) for implementing a method for loading network resources according to an embodiment of the present application;
[0035] Fig.18 It is a structural block diagram of a computing environment of a method for loading network resources according to an embodiment of the present application. DETAILED DESCRIPTION
[0036] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present application.
[0037] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to the above-mentioned process, method, product or device.
[0038] First, some nouns or terms that appear in the description of the embodiments of the present application are subject to the following explanations:
[0039] A private network is a communication network established for a specific organization or entity, and its use is limited to the organization or authorized users. Compared with public networks (such as the Internet), private networks are usually closed, secure, and under the full control and management of the organization. The purpose of a private network is to ensure the exclusivity, security, and reliability of network resources;
[0040] Front-end resources usually refer to files and materials related to user interface (UI) design and interaction in website or web application development. The above resources are mainly used to build and display the visual elements and user experience of the website, including but not limited to the following categories: Cascading Style Sheets (CSS) files, image files, font files, and multimedia files;
[0041] Front-end resource loading refers to the process in which the browser requests, downloads, and processes all front-end resources used to build and display a web page from the server when a user visits the web page.
[0042] CDN is a distributed network service that caches content in multiple data centers around the world, allowing users to obtain data from geographically close servers, thereby speeding up content loading and reducing latency;
[0043] Cookie browser is a small data file created by the website. When you visit a website, it will be sent to your browser and stored on your device. The main purpose of cookies is to allow the website to remember the user's visit, and usually contains information about the user's website preferences, browsing session, authentication status or other information used to improve the user experience;
[0044] Interceptor, in programming and software development, is a design pattern used to "intercept" the execution flow of a program at a specific code execution point in order to add additional functionality without modifying the original code. Interceptors are often used to handle cross-cutting concerns, such as logging, permission verification, transaction processing, exception handling, etc.
[0045] According to an embodiment of the present application, a method for loading network resources is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0046] The network resource loading method provided in the embodiment of the present application can be applied to Figure 1 The application scenarios shown are not limited to these. Figure 1 In the application scenario shown, the server 10 can be a cloud. The server 10 can be connected to one or more client devices (clients) 20 via a local area network connection, a wide area network connection, an Internet connection, or other types of data networks. The client devices 20 here may include but are not limited to: smart phones, tablet computers, laptops, PDAs, personal computers, smart home devices, vehicle-mounted devices, etc. The client devices together constitute the client relative to the server. An operating interface for user operation can be deployed on the graphical user interface on the client device, and the operating interface can be a cloud desktop. The client device 20 can interact with the user through a graphical user interface to implement the method for loading network resources provided in the embodiment of the present application.
[0047] In the embodiment of the present application, the system composed of the client device 20 and the server 10 can perform the following steps: if it is necessary to load a network resource on a target page, the user can perform corresponding operations on the operation interface of the client device 20 and input a page access request for the target page to be accessed. The page access request can be transmitted to the server 10 via the network. Specifically, the following steps can be performed in the server 10:
[0048] Step S102, obtaining a page access request from a client; Step S104, in response to the page access request, identifying identification information from the page access request; Step S106, determining at least one target page that matches the identification information, and network resources that match the identification information; Step S108, returning the target page to the client, and loading network resources into the target page.
[0049] In the above process, the target page and the network resources of the target page obtained in the server 10 can be sent to the client device 20 through the network. The network resources in the target page can be loaded on the client device 20.
[0050] In this embodiment, a front-end resource adaptive loading method is proposed, the core of which is to automatically determine whether the client has the authority to access CDN resources based on the identification information contained in the page access request, and return the appropriate page version accordingly, thereby realizing efficient and intelligent loading of resources without manual intervention. The above method can maintain good adaptability and performance in both public cloud and private cloud environments, thereby achieving the technical effect of improving the loading efficiency of network resources and solving the technical problem of low loading efficiency of network resources.
[0051] The embodiment of the present application proposes the following method. In the above application scenario, the present application provides the following from the server side: Figure 2 The method for loading network resources shown. Figure 2 is a flow chart of a method for loading network resources according to an embodiment of the present application, such as Figure 2 As shown, the method can be applied to a server, and a specific application instance can be run on the server, such as a website or a software instance. The following steps can be included:
[0052] Step S202: Obtain a page access request from the client.
[0053] In the technical solution provided in the above step S202 of the present application, the client may be a front end, for example, a browser. The page access request (page access request) may be sent by the client to request the server to access a page. The page may be a front end page.
[0054] In this embodiment, if it is necessary to load a network resource on a target page, a page access request for accessing the required target page may be obtained from the client.
[0055] Optionally, when a user visits a website or starts an application, the client can send a page access request and transmit it to the server through the network. Through the above method, the server can accurately identify the page access request of each client connected to it and capture it for subsequent processing.
[0056] Step S204: in response to the page access request, identifying identification information from the page access request.
[0057] In the technical solution provided in the above step S204 of the present application, the identification information can be used to indicate the client's authority to access the content distribution network (CDN), and can be an access CDN identification, for example, it can be an identification (flag) used to determine whether the client has an accessible identity.
[0058] In this embodiment, after the server obtains the page access request from the client, the page access request can be identified to determine whether the client that issued the page access request has the authority to access the CDN, that is, identification information used to determine whether there is authority to access the corresponding CDN can be identified from the page access request.
[0059] Optionally, specific identification information is extracted from the page access request sent by the client, and the identification information is used to determine whether the client has the authority to access CDN resources. The above method lays a foundation for ensuring adaptive loading of resources.
[0060] Optionally, after the server receives the page access request, the location of the identification information can be located from the page access request. The identification information may exist in multiple parts of the page access request, such as a Hypertext Transfer Protocol (HTTP) request header, a Uniform Resource Locator (URL) parameter, or a specific data field. It should be noted that the location of the above identification information in the page access request, and the process and method of how to determine the identification information from the page access request are only for illustrative purposes and are not specifically limited here.
[0061] In the embodiment of the present application, the above method is a key link in the adaptive loading strategy of network resources. By identifying identification information from the page access request, the server can intelligently determine the client's CDN access rights, thereby selecting the appropriate resource loading path (obtaining network resources from the CDN or from this site). The above process not only improves the efficiency and flexibility of CDN resource loading, but also ensures the continuity of services and user experience in various network environments. By accurately parsing and updating identification information, the server can provide customized resource loading services to the client while protecting the client's privacy and security.
[0062] Step S206: determining at least one target page matching the identification information and a network resource matching the identification information.
[0063] In the technical solution provided in the above step S206 of the present application, the page type of the target page corresponds to the authority corresponding to the identification information, that is, the target page can be a page with an access CDN identification, or a page without an access CDN identification. The source of the network resource corresponds to the authority corresponding to the identification information. The target page can also be a target web page.
[0064] In this embodiment, after identifying the identification information from the page access request, a target page matching the identification information may be determined, and a network resource (resource) matching the identification information may also be determined.
[0065] Optionally, a suitable resource loading path is selected from the identification information identified in the page access request, and according to the resource loading path, it is determined which type of target page to return and the corresponding network resource loading strategy. That is, according to the corresponding resource loading path, the corresponding type of target web page is called, and according to the corresponding network resource loading strategy, the web page resources on the target web page are loaded. If the resource loading path is CDN, the front-end resources in the corresponding target web page can be obtained from CDN. Conversely, if the resource loading path is this site, the front-end resources in the corresponding target web page can be obtained from this site.
[0066] Optionally, if the identification information indicates that the client has access to CDN resources, the server can determine a regular target page with resource links pointing to resources on the CDN. This means that the server will directly return a standard, unmodified version of the page that contains the path to the CDN resource. That is, when the identification information shows that the client can access CDN resources, the server will give priority to the CDN resource loading strategy to take advantage of the fast, low-latency resource access capabilities provided by the CDN.
[0067] Optionally, if the identification information indicates that the client cannot access CDN resources, that is, the client can only obtain the target web page from this site, the server will determine a "target page using resources from this site". This page version has been modified or generated in advance, and the links to the resources in it are adjusted to point to resources on the local server or private network to ensure that the page can be loaded and displayed normally even when the network is isolated. In other words, if the identification information shows that the client cannot access CDN resources, the server will adopt a local resource loading strategy to ensure the stability and availability of resources and avoid service interruptions due to CDN access restrictions.
[0068] In the embodiment of the present application, the above method is a decision point in the front-end resource adaptive loading mechanism. The server selects the appropriate page type and resource loading path based on the identification information, which not only ensures that clients with different network environments and permission levels can obtain appropriate resource loading effects, but also protects the stability of the service and the consistency of the data. By intelligently matching the target page and network resources, the server can provide the client with a resource loading service with strong adaptability and excellent performance.
[0069] Step S208, returning the target page to the client, and loading network resources into the target page.
[0070] In the technical solution provided in the above step S208 of the present application, the client may be a browser or other rendering engine. The client is used to connect to the server and send a page access request to the server.
[0071] In this embodiment, after determining the target page that matches the identification information and the network resource that matches the identification information, the target page can be returned to the client, and the network resource can be loaded on the target page on the client.
[0072] Optionally, the target page and corresponding network resources selected by the server according to the identification information are returned to the client, ensuring that the client can load the correct resources according to the client's access rights to the CDN.
[0073] Optionally, after determining the target page that matches the identification information, the server can construct a response containing the content of the page. The response will contain all necessary resource references, which point to CDN resources or local resources based on the identification information. The content type of the response can match the page type of the target page requested by the client.
[0074] Optionally, the server generates a resource link related to the target page, and the resource link can be used to determine the source of the determined network resource. If the client has access to the CDN, the resource link will point to the resource on the CDN; if the client cannot access the CDN, the resource link will point to the resource on the site (for example, a local server or a private network). That is, based on the identification information, a resource link corresponding to the target page can be generated. Through the resource link, the target page can be indexed from the source of the corresponding network resource.
[0075] Optionally, after the server responds to the identification information and determines the corresponding target web page and the network resources to be loaded in the target web page, the server can send the target page to the client via an HTTP response. For example, the target page can be sent to the client in a responsive Hypertext Markup Language (HTML) document. The HTTP response can include an HTTP status code, a response header, and a response body, and the response body includes the type of data required by the target page. When the server sends a response, a secure transmission protocol such as HTTPS can be used for data encryption and transmission.
[0076] Optionally, after the client receives the HTML document sent by the server, it can parse the HTML document to parse out the tags, attributes, and content of the target page. Based on the relationship between the above attributes and content, a Document Object Model (DOM) tree can be created. During the DOM tree construction process, the network resources required to be loaded in the target page can be identified, such as CSS style sheets, images, font files, etc. The above network resources are usually <link> , <script>、等HTML标签中的src或href属性进行定位。一旦定位到所需加载的网络资源,可以获取相应的网络资源。对所获取的网络资源可以按照相应顺序进行调度和加载,加载完成之后,可以在客户端上进行目标页面的渲染。也即,在目标页面上的网络资源加载完成并被正确解析之后,可以在客户端上呈现渲染后的目标页面给用户。
[0077] 在本申请实施例中,确保了客户端能够根据自身对CDN进行访问的权限,加载适宜的资源。上述方法不仅提高了资源加载的效率和可靠性。通过动态生成和发送响应,以及客户端的智能资源加载策略,上述方法克服了传统静态资源加载方式的局限性,为用户提供了一个更加灵活、高效的服务体验。
[0078] 通过本申请上述步骤S202至步骤S208,若需要对网络资源进行加载,则可以实时监测客户端是否具有访问某一页面(也即,前端页面)的请求,也即,页面访问请求。若监测到页面访问请求,可以从其中分析出该客户端是否有对CDN进行访问的权限对应的标识信息。若访问请求中没有上述标识信息,则无法对该页面中的网络资源进行加载,反之,则可以确定出与标识信息中的权限所匹配的可访问的至少一目标页面。并可以将该目标页面返回至相应的客户端,并在客户端上对该目标页面上的网络资源进行加载。在该实施例中,提出了一种前端资源自适应加载方法,其核心在于能够根据页面访问请求中所包含的标识信息自动判断客户端是否具备访问CDN资源的权限,并据此返回合适的页面版本,从而在无需人工介入的情况下,实现资源的高效、智能加载。上述方法在公有云和专有云环境下均能保持良好的适应性和性能,从而实现了提高网络资源的加载效率的技术效果,解决了网络资源的加载效率低的技术问题。
[0079] 下面对该实施例的上述方法进行进一步的介绍。
[0080] 作为一种可选的实施方式,步骤S206,确定与标识信息相匹配的至少一目标页面,以及与标识信息相匹配的网络资源,包括:响应于标识信息表示允许客户端访问内容分发网络,确定与内容分发网络相匹配的至少一第一类型页面,以及来自内容分发网络的网络资源;响应于标识信息表示禁止客户端访问内容分发网络,确定与内容分发网络对应的本站相匹配的至少一第二类型页面,以及来自本站的网络资源,其中,网络资源允许由本站缓存至内容分发网络上。
[0081] 在该实施例中,在确定与标识信息相匹配的目标页面以及网络资源的过程中,可以确定标识信息是表示允许客户端访问CDN还是不允许客户端访问CDN。若允许客户端访问CDN,则可以确定出与CDN相匹配的第一类型页面,以及来自CDN的网络资源。反之,若不允许客户端访问CDN,则可以确定与内容分发网络相对应的本站相匹配的第二类型页面,以及来自本站的网络资源。其中,第一类型页面可以为使用CDN资源的页面1~页面N,比如,可以为普通的页面。第二类型页面可以为使用本站资源的页面1~页面N,也即,第二类型页面上的前端资源通过本站进行加载。
[0082] 可选地,本站可以指原始网站或服务器,即Web应用或网站的资源最初存放和管理的地方。与CDN相对,CDN是一种分布式的网络服务,它将网站的静态资源(如图片、JavaScript文件、CSS文件等)复制到全球多个节点服务器上,当用户访问网站时,静态资源可以从离用户地理位置最近的服务器上加载,从而减少延迟,提高加载速度和用户体验。而本站则位于Web应用或网站,是资源的原生存储地。在没有使用CDN的情况下,或者在CDN资源不可用时,客户端将直接从本站获取资源。
[0083] 可选地,当CDN资源不可访问时,本站可以提供一个资源的备份,确保网页或应用仍然能够正常加载所需的资源,即使这些资源无法从CDN获取。通过标识信息(如Cookie中的CDN访问状态),服务器可以判断客户端是否能够访问CDN。如果客户端可以访问CDN,本站将返回使用CDN资源的页面版本;如果客户端无法访问CDN,本站将返回使用本站资源的页面版本,从而自适应网络状况,保证资源的可用性和加载效率。本站可以是资源的原始来源,通常由网站或应用的开发者直接控制和管理,包括资源的更新、版本控制和安全性。
[0084] 可选地,网络资源允许由本站缓存至内容分发网络上,意味着本站不仅能够提供资源,还可以将资源缓存到CDN上,以提高后续用户访问时的资源加载速度。本站通过缓存策略控制哪些资源需要缓存到CDN,以及缓存的有效期等参数。
[0085] 综上所述,本站既是资源的原始来源,也是在CDN无法访问时的备用资源提供者,通过与CDN的配合使用,本站能够提供更稳定、更快速的资源加载服务,同时保证数据的安全和完整性。
[0086] 可选地,在使用CDN技术的场景中,与CDN对应的本站为原始存放和管理网站或Web应用资源的服务器或服务器集群。上述资源包括但不限于HTML页面、CSS样式表、JavaScript脚本、图片、字体文件和多媒体文件等。在CDN的工作流程中,本站是资源的源头,CDN则是本站资源的缓存和分发点。
[0087] 具体地,本站是网络资源(资源)的始发地。开发者在本站上存储和更新资源,CDN从本站获取最新的资源版本,并将其分发到全球范围内的节点服务器上,以加速用户访问。本站服务器负责资源的版本控制、数据完整性验证和安全检查。所有资源在上传到CDN节点之前,可以通过本站的验证,确保CDN分发的资源与本站上的资源保持一致。在CDN服务异常或网络无法访问CDN时,本站能够直接提供资源,以确保网站或Web应用的正常运行,避免用户因资源加载失败而受到不良体验。本站通过动态缓存策略与CDN进行交互,决定哪些资源需要缓存到CDN节点,以及缓存的有效期等参数。这确保了本站上的最新资源能及时更新到CDN节点上,同时避免过期资源在CDN中停留过久。本站能够通过客户端传递的标识信息(如Cookie中的CDN访问状态),判断客户端是否能够访问CDN,从而决定是提供通过CDN加载资源的页面版本,还是直接通过本站服务器加载资源的页面版本,实现资源加载的自适应和优化。
[0088] 可选地,本站上的网络资源和CDN节点上的网络资源之间存在着一一对应的关系,即每个本站资源在CDN上都有对应的缓存版本,且CDN版本的更新依赖于本站资源的变化。
[0089] 综上所述,具备资源原始存储、管理、更新以及在CDN失效时作为后备资源提供者功能的网站或服务器。它与CDN保持着密切的互动和依赖关系,确保了即使在网络环境变化或CDN服务出现故障的情况下,网站或Web应用仍然能够快速、稳定地为用户提供服务。
[0090] 可选地,服务器可以分析从页面访问请求中所提取的标识信息,以判断客户端是否被允许访问CDN。这一判断基于标识信息中携带的特定标记或参数,上述信息可以是布尔值(比如,允许(true)、禁止(false))、特定的CDN域名列表或是其他的权限标识形式。如果标识信息表明客户端可以访问CDN资源,服务器将进入允许访问CDN的处理路径;反之,则进入禁止访问CDN的处理路径。
[0091] 可选地,若服务器进入允许访问CDN的处理路径,服务器可以确定与标识信息相匹配的第一类型页面,即这些页面设计为使用CDN上的资源进行加载。这些页面可能包括页面1到页面N,每一个都与CDN资源有直接的链接或引用。服务器确保第一类型页面上的网络资源链接指向CDN上的资源。这些资源可能包括但不限于CSS文件、图像文件、音频或视频文件等。通过直接引用CDN上的资源,可以利用CDN的全球缓存和分发能力,提高资源加载速度,降低主服务器的负载。
[0092] 可选地,若服务器进入禁止访问CDN的处理路径,服务器可以确定与标识信息相匹配的第二类型页面。上述页面预先设计用于仅通过本地服务器加载资源,确保即使在没有CDN访问权限的情况下,页面内容仍然能够正常显示和交互。服务器将第二类型页面上的网络资源链接指向本地服务器或专有网络内的资源。上述资源可能已经在本地有缓存或副本,以确保资源的快速访问。
[0093] 可选地,网络资源允许由本地服务器缓存至CDN上。这意味着本地服务器不仅需要能够检测和响应CDN访问状态,还应当具备将本地资源推送到CDN的服务能力。这样一来,即使客户端最初无法访问CDN,通过本地服务器的资源上传和更新,未来客户端可能重新获得CDN访问权限时,能够立即利用CDN的资源,而无需等待本地资源的再次上传。这种双向兼容性确保了方案的灵活性和资源使用的高效性。
[0094] 在本申请实施例中,通过上述方法中根据标识信息动态地确定是从CDN确定目标页面,还是从本站资源(本站的网络资源)中确定目标网络,也即,上述方法体现了网络资源的加载灵活性,既能适应CDN可访问的情况,也能应对CDN访问受限的专有网络环境。此外,通过允许本地资源上传到CDN,还可以根据网络状况或访问需求的变化进行动态调整,使得资源加载策略能够随着网络环境的演变而自我调整。通过自动检测客户端的CDN访问权限,并根据权限调整资源加载路径,确保了在各种网络条件下用户都能够获得顺畅的网页加载体验。同时,上述方法还考虑了资源管理的效率,通过本地缓存和CDN上传的结合,减少了资源加载的延迟,降低了服务器的负载。
[0095] 综上所述,上述方法是整个自适应加载方案中的核心决策点,可以基于标识信息的分析,智能地调整页面类型和资源加载策略,既提高了资源加载的效率,也确保了服务的连续性和用户体验,无论客户端是处于可访问CDN的公有云环境,还是受限于访问权限的专有网络环境。
[0096] 作为一种可选的实施方式,将目标页面返回至客户端,且向目标页面加载网络资源,包括:在标识信息表示允许客户端访问内容分发网络的情况下,将第一类型页面返回至客户端;在第一类型页面在客户端上运行的过程中,向第一类型页面加载来自内容分发网络的网络资源。
[0097] 在该实施例中,在将目标页面返回至客户端,且向目标页面加载网络资源的过程中,若标识信息表示允许客户端访问内容分发网络,可以将第一类型页面返回至客户端,在客户端上运行第一类型页面,并在第一类型页面上加载来自内容分发网络的网络资源。
[0098] 可选地,在标识信息表示允许客户端访问内容分发网络的情况下,当服务器通过标识信息确认客户端具备访问CDN的权限时,可以选择并返回第一类型页面。服务器根据客户端请求的具体页面类型,从预先准备的第一类型页面库中选取对应页面,并将其完整的内容作为HTTP响应发送给客户端。响应体中包含了页面HTML、必要的资源链接以及任何动态数据或脚本。
[0099] 可选地,客户端接收到服务器返回的第一类型页面后,浏览器开始解析并渲染页面。在解析过程中,浏览器会识别HTML文档中嵌入的资源链接,并根据这些链接发起对CDN资源的请求。在客户端上运行第一类型页面的过程中,浏览器可以尝试加载页面中提及的CDN资源。上述资源请求通常通过HTTP / HTTPS协议进行,浏览器会根据CDN资源的URL,选择最近的CDN节点进行下载。CDN的全球分布特性确保资源加载速度快、延迟低,提高了整体的用户体验。
[0100] 可选地,在资源加载过程中,浏览器会使用缓存机制来存储已下载的资源,以减少未来加载相同资源所需的网络请求。CDN通常也采用缓存策略,使得资源请求在客户端和CDN节点之间都能得到调整。
[0101] 在本申请实施例中,利用CDN能够显著提高资源加载速度,减少延迟,提升用户体验。这是因为CDN能够根据用户的位置提供最近的资源服务器,以及CDN本身的缓存和调整机制。通过CDN加载资源,可以大大减少主服务器的带宽消耗和负载,因为CDN节点可以承担大量的资源请求。即使在CDN暂时无法访问的情况下,页面设计中的自适应加载机制可以确保网站或软件仍然能够通过本地资源加载,提供基本的功能和服务。上述方法允许根据客户端的网络状况和权限动态调整资源加载策略,提高了系统的灵活性和适应不同网络环境的能力。同时,设计考虑了未来网络状况变化的可能性,通过CDN与本地资源的结合使用,确保了无论CDN是否可用,都能提供合适的资源加载体验。
[0102] 综上所述,当标识信息表示客户端可以访问CDN时,此实施方式充分利用CDN的优势,以提高资源加载的效率和用户体验。同时,还可以通过内置的自适应机制确保了在CDN访问受限时,服务的连续性和可用性,体现了方案的智能与高效。
[0103] 作为一种可选的实施方式,将目标页面返回至客户端,且向目标页面加载网络资源,包括:在标识信息表示禁止客户端访问内容分发网络的情况下,将第二类型页面返回至客户端;在第二类型页面在客户端上运行的过程中,向第二类型页面加载来自本站的网络资源。
[0104] 在该实施例中,在将目标页面返回至客户端,且向目标页面加载网络资源的过程中,若标识信息表示禁止客户端访问内容分发网络,可以将第二类型页面返回至客户端,在客户端上运行第二类型页面,并在第二类型页面上加载来自本站的网络资源。
[0105] 可选地,在标识信息表示禁止客户端访问内容分发网络的情况下,当服务器通过标识信息确认客户端被禁止访问CDN时,可以返回第二类型页面作为响应。第二类型页面,与第一类型页面不同,其前端资源(如CSS、图片、字体等)的链接都指向本地服务器或专有网络内的资源。这意味着服务器在构建响应时,会使用一套完全本地化的资源链接,以确保即使在CDN不可用的环境下,页面也能正常加载和运行。服务器从其资源库中选取与请求页面类型相匹配的第二类型页面,将其HTML代码、内嵌资源链接以及任何动态数据一并封装为HTTP响应,发送给客户端。
[0106] 可选地,客户端接收到服务器返回的第二类型页面后,浏览器开始解析并渲染页面。在解析过程中,浏览器识别出页面中所有资源的本地链接,并向本地服务器或专有网络内的资源服务器发起下载请求。在客户端上运行第二类型页面的过程中,所有资源请求都指向本地服务器或专有网络内的资源服务器。这确保了资源加载不会受到CDN访问限制的影响,即使在客户端完全无法访问CDN的情况下,页面也能通过本地资源加载完成渲染,提供完整的服务和功能。本地资源的加载同样可以利用浏览器的缓存机制,以减少重复的网络请求和提高加载速度。对于动态资源或需要实时更新的资源,客户端会通过与本地服务器的直接通信来获取,避免了CDN缓存机制的延迟问题。
[0107] 在本申请实施例中,即使在CDN服务不可用或受限的情况下,第二类型页面也能通过本地资源加载,保证了服务的持续可用性和用户体验的一致性。资源完全从本地服务器获取,减少了外部网络的依赖,增强了数据的安全性和隐私保护,尤其适合对数据安全有严格要求的场景。避免了CDN访问的不确定性,减少了对外部网络的依赖,从而在某些网络环境下(如专有网络)可以提供更稳定的网络性能。这一机制展示了方案的自适应性,能够根据网络环境和策略的变化,自动调整资源加载方式,保证了服务的灵活性。
[0108] 综上所述,当标识信息表示客户端禁止访问CDN时,通过返回并运行第二类型页面,以及加载来自本地的网络资源,此实施方式确保了页面在任何网络条件下都能够正常加载并运行,同时增强了数据的安全性和隐私保护。这种自适应的加载机制,再次体现了方案在不同网络环境下提供一致用户体验的能力,以及对资源加载策略的智能调整。
[0109] 作为一种可选的实施方式,步骤S204,响应于页面访问请求,从页面访问请求中识别出标识信息,包括:响应于页面访问请求,从页面访问请求中获取数据文件,其中,数据文件由客户端存储;从数据文件中识别出标识信息。
[0110] 在该实施例中,在从页面访问请求中,识别出标识信息的过程中,可以从页面访问请求中获取数据文件,并从数据文件中识别出标识信息,其中,数据文件可以由客户端存储,可以为Cookie。
[0111] 可选地,当客户端(比如,Web浏览器)向服务器发出页面访问请求时,服务器响应的第一步是解析请求。在这些请求中,通常会携带一些额外的信息,比如,用户代理、请求头、Cookie等,上述信息提供关于请求上下文和客户端状态的详细数据。在本实施例中,服务器关注的焦点是请求中携带的数据文件,通常是Cookie。
[0112] 可选地,在客户端存储的数据文件中,Cookie用于存储关于用户会话状态、偏好设置、访问历史等信息。当客户端访问服务器时,Cookie可以自动附加在请求头上发送给服务器,因此服务器可以从中获取各种标识信息,包括关于客户端是否允许访问CDN资源的信息。
[0113] 可选地,服务器在接收到页面访问请求后,通过解析请求头中的Cookie数据,能够从中识别出特定的标识信息。具体地,服务器可以识别哪些Cookie数据与CDN访问权限相关联。一旦找到相关的Cookie,服务器将解析其内容,理解其中的标识信息。基于解析出的标识信息,服务器做出决策,确定客户端是否被允许访问CDN,以及应当返回哪种类型的目标页面(第一类型页面或第二类型页面)。
[0114] 可选地,服务器可以事先了解Cookie的格式和存储标识信息的具体方式,这样才能正确解析出标识信息。这可能涉及到对Cookie的键名、值格式和编码的了解。在处理Cookie中的标识信息时,服务器需要确保数据的安全性,防止标识信息被篡改或未授权访问,从而影响资源加载策略的正确实施。服务器应当考虑到不同客户端可能有不同的Cookie处理方式,确保标识信息的识别和解析能够在各种设备和浏览器上正常工作。虽然Cookie是获取标识信息的常用方法,但服务器在解析Cookie时需要注意性能影响。大量的Cookie数据可能会影响请求处理速度,因此在设计时应调整数据传输和解析过程,以减少对服务器性能的影响。
[0115] 在本申请实施例中,通过从客户端页面访问请求中携带的Cookie数据文件中识别标识信息,实现了服务器对客户端CDN访问权限的智能感知。这一过程是自适应加载方案中关键的第一步,决定了后续步骤中目标页面和资源加载策略的选择,从而确保了在不同网络环境下,客户端能够获得相应的资源加载体验,同时保持了服务的连续性和安全性。通过智能识别标识信息并进行权限判定,服务器能够动态调整其响应,以适应客户端的特定需求和网络状况。
[0116] 作为一种可选的实施方式,从页面访问请求中获取数据文件,包括:调用拦截器,从页面访问请求中获取数据文件。
[0117] 在该实施例中,在从页面访问请求中获取数据文件的过程中,可以调用拦截器(Interceptors),从页面访问请求中读取数据文件。其中,拦截器可以为页面访问拦截器。
[0118] 可选地,使用拦截器从页面访问请求中提取数据文件。其中,拦截器是一种设计模式,用于在请求处理流程中拦截或修饰HTTP请求和响应。当客户端向服务器发送页面访问请求时,服务器端框架或自定义服务可以配置一个或多个拦截器来处理请求。
[0119] 可选地,页面访问拦截器在请求处理的早期阶段被调用,其主要职责是从请求中提取必要的信息,如请求头、cookie等。在本申请实施例中,拦截器被设计为专门从请求中读取数据文件,通常是cookie,以获取标识信息,这些信息关于客户端是否能够访问CDN资源。拦截器接收到请求后,将从请求头中查找并读取数据文件。数据文件通常以特定的键值对形式存储在cookie中,其中键是预先定义的,用于标识与CDN访问策略相关的信息。读取cookie中数据文件的过程涉及解析HTTP请求头,查找特定的cookie键值对,并从中提取标识信息。
[0120] 可选地,拦截器在读取并解析数据文件中的标识信息后,将该信息传递给后续的处理流程。这一信息对于后续步骤奠定基础,因为该信息决定了服务器向客户端返回哪种类型的目标页面以及网络资源加载的策略。标识信息的处理可能包括对数据的验证,以确保其格式正确且未被篡改。此外,服务器可能需要将标识信息转换为更易处理的内部格式,或是存储在会话变量中,以供后端逻辑使用。
[0121] 在本申请实施例中,页面访问拦截器的配置是实现这一实施方式的关键。在服务器端,开发者需要确保拦截器被正确地注册并置于请求处理链的适当位置,以便在请求到达目标处理逻辑之前截获并解析数据文件。拦截器的作用不仅限于读取标识信息,还可以执行其他任务,如日志记录、性能检测、安全检查等,这些都与请求处理的全局关注点相关。在本实施例中,拦截器的焦点是读取和处理数据文件中的标识信息,以支持前端资源的自适应加载。调用页面访问拦截器并从页面访问请求中读取数据文件,是整个自适应加载方案中信息提取的关键环节。利用了拦截器的设计模式,以灵活和高效的方式处理请求,确保服务器能够准确地根据客户端的CDN访问状态做出响应,从而提供调整的前端资源加载体验。
[0122] 作为一种可选的实施方式,从数据文件中识别出标识信息,包括:利用拦截器,从数据文件中识别出内容分发网络的域名;利用拦截器,获取与域名关联的标识信息,其中,标识信息用于表示客户端对内容分发网络的域名进行访问的权限。
[0123] 在该实施例中,在从数据文件中识别出标识信息的过程中,可以利用拦截器从数据文件中识别出内容分发网络的域名。并获取与上述域名相关联的标识信息。其中,标识信息可以用于表示客户端对内容分发网络的域名进行访问的权限。
[0124] 可选地,利用页面访问拦截器来从数据文件中识别出标识信息,特别是与内容分发网络(CDN)域名访问权限相关的标识信息。
[0125] 可选地,页面访问拦截器在接收到客户端的页面访问请求时,会首先介入请求处理流程。其任务之一是分析客户端提供的数据文件,上述数据文件可能包括在请求头中的cookie。拦截器可以专门寻找与CDN域名访问状态相关的信息。具体来说,拦截器会扫描cookie中的每一个键值对,寻找特定的键,上述键被设计用来存储CDN域名信息或,与之相关联的状态信息。
[0126] 可选地,拦截器通过解析上述键的值,能够识别客户端是否被允许访问特定的CDN域名。这一步骤对于后续资源加载策略的决策奠定基础,因为在不同的网络环境下,客户端的CDN访问能力可能有所不同,从而影响资源加载的效率和可靠性。一旦拦截器识别出了CDN域名,接下来的步骤是获取与这些域名相关联的标识信息。标识信息通常直接存储在从数据文件中读取的值中,或者可能需要进一步处理和转换才能获得。
[0127] 标识信息的形式可能有多种,从简单的布尔值(true或false,表示是否允许访问CDN)到更复杂的结构体,如包含域名、访问状态、有效期等信息的JSON对象。拦截器可以设计有适当的逻辑,能够根据数据文件中的值,正确解读出客户端的CDN访问权限状态。
[0128] 拦截器获取到的标识信息将被用于后续的决策步骤中,例如,可以确定目标页面和资源加载策略。如果标识信息指示客户端可以访问CDN,服务器将优先选择从CDN加载资源的第一类型页面;如果标识信息指示客户端禁止访问CDN,服务器将选择从本地加载资源的第二类型页面。
[0129] 在本申请实施例中,通过利用拦截器从数据文件中识别CDN域名及其访问权限的标识信息,服务器能够智能地判断客户端的网络状况和访问需求,从而做出最适合的响应。上述机制展示了方案的灵活性,能够适应各种网络环境和客户端配置,确保资源加载既高效又可靠。
[0130] 作为一种可选的实施方式,该方法还包括:响应于从页面访问请求中识别标识信息失败,确定与内容分发网络相匹配的至少一第一类型页面,以及来自内容分发网络的网络资源。
[0131] 在该实施例中,若从页面访问请求中识别标识信息失败,则可以确定与CDN相匹配的第一类型页面,以及来自CDN的网络资源。
[0132] 可选地,上述方法旨在解决从页面访问请求中识别标识信息失败的情况,确保即便在这一关键的标识信息缺失的条件下,也能够做出合理的响应,以维持服务的可用性和用户体验。
[0133] 可选地,当页面访问拦截器尝试从数据文件(如Cookie)中解析CDN访问权限标识信息时,可能会遇到以下几种失败情形:数据文件不存在,也即,客户端可能没有存储必要的Cookie,或者由于隐私设置等,Cookie没有随请求发送;数据格式错误,也即,Cookie中的标识信息可能因为某种原因而变得不可读或不符合预期的格式;通信错误,也即,在某些极端情况下,请求或响应可能受到干扰,导致数据文件无法正确接收或读取。无论哪种情况,如果标识信息无法被正确识别,服务器将无法确定客户端是否能够访问CDN资源,也就无法根据标识信息做出资源加载策略的决策。
[0134] 可选地,为了应对标识信息识别失败的情况,服务器需要采取一种预设的策略。在这种可选实施方式中,服务器将默认选择第一类型页面,即可以从CDN加载资源的页面。第一类型页面通常会从多个源加载资源,包括CDN和本地服务器,这提供了一种冗余机制,即使CDN资源暂时不可用,也可以从本地服务器获取资源,确保页面的可用性。CDN资源由于其全球分布特性,通常能够提供较快的加载速度和较低的延迟,对于大多数用户来说,这是合适的选择。CDN的缓存机制可以减少对本地服务器的直接请求,从而节省本地服务器的带宽和计算资源。
[0135] 本申请实施例从浏览器侧,还提供了一种网络资源的加载方法,图3是根据本申请实施例的一种网络资源的加载方法的流程图,如图3所示,该方法应用于客户端,可以包括以下步骤:
[0136] 步骤S302,向服务器发送页面访问请求,其中,页面访问请求用于向服务器请求访问页面。
[0137] 在本申请上述步骤S302提供的技术方案中,在客户端侧,当用户发起页面访问操作,比如,通过点击链接、输入URL或刷新页面时,Web浏览器会开始构建一个页面访问请求。请求中包含了访问目标页面所需的完整URL、HTTP方法以及其他必要的头部信息等,用于描述客户端的环境和能力。
[0138] 可选地,为了使服务器能够根据客户端的网络状况和CDN访问能力做出响应,客户端需要在其页面访问请求中封装标识信息。上述标识信息通常存储在Cookie中,但也可以是其他形式的数据文件。其中,标识信息包括但不限于以下内容:CDN访问状态(允许或禁止)、最近一次检测CDN访问能力的时间以及CDN访问失败的次数(用于服务器调整决策)。封装标识信息的目的是让服务器能够根据这些信息判断客户端的CDN访问权限和网络状况,从而决定返回第一类型页面(使用CDN资源)还是第二类型页面(使用本地资源)。
[0139] 可选地,客户端构建好页面访问请求后,将通过网络发送给服务器。这一发送过程可能涉及多层协议的封装,从应用层的HTTP请求,到传输层的TCP / IP封装,再到网络层的路由选择和数据包传输。
[0140] 步骤S304,加载服务器响应页面访问请求,而返回的至少一目标页面,且在目标页面上加载对应的网络资源,其中,标识信息用于表示客户端对内容分发网络进行访问的权限,目标页面的页面类型与标识信息对应的权限相对应,网络资源的来源与标识信息对应的权限相对应。
[0141] 在本申请上述步骤S304提供的技术方案中,在向服务器发送页面访问请求之后,可以加载服务器响应页面访问请求所返回的目标页面,并在目标页面中加载对应的网络资源。
[0142] 可选地,客户端(通常是Web浏览器)接收并处理服务器响应,加载目标页面及其对应的网络资源。上述方法是自适应加载方案中客户端行为的核心,确保了用户能够根据其网络状况和CDN访问权限加载合适的页面资源。
[0143] 可选地,当客户端向服务器发送了页面访问请求,可以等待服务器的响应。响应通常包含一个HTTP状态码,表示请求是否成功,以及一个响应体,其中包含目标页面的HTML代码。在本申请的实施例中,响应体还可能包含有关资源加载策略的额外信息,这些信息被用于指导客户端后续的资源加载行为。
[0144] 可选地,客户端接收到响应后,首先解析响应体中返回的HTML代码,以确定目标页面的类型。在本自适应加载方案中,目标页面可以是第一类型页面(设计为优先从CDN加载资源)或第二类型页面(设计为仅从本地服务器加载资源)。目标页面类型的选择直接依赖于服务器根据页面访问请求中的标识信息所做出的决策。标识信息(如Cookie中的CDN访问权限状态)被用于服务器的这一判断,确保了返回的目标页面与客户端的实际网络状况和CDN访问能力相匹配。
[0145] 可选地,一旦确定了目标页面的类型,客户端将根据页面中的资源链接加载对应的网络资源。对于第一类型页面,这些资源链接指向CDN服务器,利用CDN的分发和缓存能力,以提高资源加载速度和响应性能。对于第二类型页面,资源链接指向本地服务器,确保即使在无法访问CDN的情况下,页面也能正常加载和运行。
[0146] 通过本申请上述步骤S302至步骤S308,向服务器发送页面访问请求;加载服务器响应页面访问请求,而返回的至少一目标页面,且在目标页面上加载对应的网络资源。在该实施例中,提出了一种前端资源自适应加载方法,其核心在于能够根据页面访问请求中所包含的标识信息自动判断客户端是否具备访问CDN资源的权限,并据此返回合适的页面版本,从而在无需人工介入的情况下,实现资源的高效、智能加载。上述方法在公有云和专有云环境下均能保持良好的适应性和性能,从而实现了提高网络资源的加载效率的技术效果,解决了网络资源的加载效率低的技术问题。
[0147] 下面对该实施例的上述方法进行进一步的介绍。
[0148] 作为一种可选的实施方式,客户端存储有数据文件,数据文件包括标识信息,步骤S302,向服务器发送页面访问请求,包括:向服务器发送携带有数据文件的页面访问请求。
[0149] 在该实施例中,在向服务器发送页面访问请求的过程中,可以向服务器发送携带有数据文件的页面访问请求。其中,客户端存储有数据文件。数据文件中包括标识信息。
[0150] 可选地,客户端在向服务器发送页面访问请求时,携带包含标识信息的数据文件,这一过程是实现自适应加载方案中客户端与服务器间通信的关键。
[0151] 可选地,客户端可以存储数据文件,这些文件通常包含在浏览器的本地存储系统中,如Cookie。数据文件中最重要的信息是标识信息,用于表示客户端对于内容分发网络(CDN)的访问权限。
[0152] 可选地,当用户通过Web浏览器访问页面时,浏览器将构建一个HTTP请求,其中包含请求URL、HTTP方法、请求头和可能的请求体。在本申请实施例中,客户端需要在构建请求时,将数据文件(特别是包含标识信息的Cookie)添加到请求头中。
[0153] 可选地,在客户端构建好携带有数据文件的页面访问请求后,将通过网络发送给服务器。在发送过程中,数据文件的安全传输是必要的,通常应使用HTTPS协议,以加密传输并防止数据在传输过程中被截获或篡改。服务器接收到请求后,会读取请求头中的Cookie及其标识信息,用于判断客户端是否能够访问CDN资源。这一信息对于确定目标页面类型(第一类型页面或第二类型页面)以及资源加载策略是较为重要的。
[0154] 可选地,如果标识信息指示客户端允许访问CDN资源,服务器将优先从CDN返回资源;反之,如果标识信息禁止访问CDN,服务器将仅从本地资源服务器返回资源,以避免加载失败和提供更稳定的用户体验。
[0155] 可选地,通过在页面访问请求中携带标识信息,客户端与服务器间的交互变得更加智能和自适应。服务器可以根据客户端的实时网络状态做出响应,选择合适的资源加载路径。同时,这种机制还允许服务器在多次请求中持续调整其响应策略,例如,如果服务器接收到的连续请求标识信息都表明客户端无法访问CDN,可能会默认返回第二类型页面,以减少资源加载失败的可能性。
[0156] 作为一种可选的实施方式,该方法还包括:响应于向内容分发网络请求在第一类型页面上加载网络资源失败,向内容分发网络对应的本站请求在第一类型页面上加载网络资源,且向数据文件添加标识信息,其中,网络资源允许由本站缓存至内容分发网络上,标识信息用于表示禁止客户端访问内容分发网络。
[0157] 在该实施例中,当向CDN分发网络请求的第一类型页面上加载网络资源失败时,可以向CDN对应的本站请求在第一类型页面上加载网络资源,且向数据文件添加标识信息。其中,网络资源可以为允许由本站缓存至内容分发网络上。标识信息可以用于表示禁止客户端访问CDN。
[0158] 可选地,上述方法针对在尝试从内容分发网络(CDN)加载资源失败后,客户端如何调整资源加载策略,并更新标识信息以反映其CDN访问状态的问题。
[0159] 可选地,客户端在收到服务器返回的第一类型页面(设计为优先从CDN加载资源)后,会尝试加载页面中引用的所有网络资源。这一加载过程可能因网络问题、CDN服务中断或客户端权限限制等各种原因而失败。客户端脚本可以监听资源加载过程中的任何错误事件,如网络请求超时、服务器返回错误状态码(如404或500)、资源格式错误等。一旦检测到资源加载失败,客户端将触发进一步的处理流程,以确保页面的完整加载和功能实现。
[0160] 可选地,当从CDN加载资源失败时,客户端应立即切换资源加载策略,向本地服务器(简称"本站”)发起资源请求。这一请求通常利用动态创建的图片标签(``)、链接外部样式表文件标签(`<link>`)或加载并执行外部脚本语言(比如,JavaScript)标签(`<script>`标签),将源属性(`src`)或链接属性(`href`)属性设置为本地服务器上的资源路径。其中,标签用于嵌入图片资源。当CDN上的图片资源加载失败时,浏览器动态创建一个新的标签,并将src属性设置为本地服务器上对应图片资源的路径,从而尝试从本地服务器加载图片资源。<link>标签通常用于链接外部样式表文件。当CDN上的CSS样式表加载失败时,浏览器可以创建一个新的<link>标签,将href属性设置为本地服务器上等效的CSS样式表的路径,从而确保页面的样式显示正常。<script>标签用于加载并执行外部JavaScript脚本。当CDN上的JavaScript文件加载失败时,浏览器将创建一个新的<script>标签,将src属性设置为本地服务器上的JavaScript资源路径,以实现脚本的本地加载和执行。
[0161] 值得注意的是,为了实现上述机制,本地服务器需要缓存有与CDN上相同或等效的资源。在开发阶段,可以通过自动化脚本或工具将CDN资源下载并存储到本地服务器上,以保证资源的可用性和一致性。
[0162] 可选地,在资源加载失败并从本地服务器成功获取资源后,客户端还需要更新其存储的数据文件中的标识信息,例如在Cookie中添加或更新一个键值对,其键名为`CDNAccessDenied`或类似,值为`true`,表示客户端禁止访问CDN资源。
[0163] 可选地,向本地服务器请求资源和更新标识信息的过程应当以异步方式进行,即在不影响页面其他部分加载和功能的情况下,独立地处理资源加载失败的情况。异步处理机制可以避免页面渲染的阻塞,确保用户能够尽快看到页面的可用内容,同时后台继续尝试加载其他资源或更新标识信息。一旦客户端的标识信息被更新为禁止访问CDN资源,将影响后续的所有页面访问请求。服务器将根据这一标识信息,优先返回第二类型页面,即那些设计为使用本地资源的页面。这有助于避免重复的资源加载失败,并提供更稳定和一致的用户体验。
[0164] 可选地,为了确保标识信息能够在用户会话期间保持一致,客户端需要将数据文件持久化存储,例如存储在Cookie中,使其在用户关闭浏览器窗口或标签页后仍能保留。这有助于服务器在用户重新访问时做出恰当的资源加载策略决策。
[0165] 在本申请实施例中,通过上述方法,客户端在CDN资源加载失败时能够迅速调整策略,从本地服务器请求资源,并通过更新标识信息向服务器传达其CDN访问状态,从而实现资源加载的自适应性和系统响应的智能性。这一机制确保了在多变的网络环境下,用户仍然能够获得高效、稳定和安全的页面加载体验。
[0166] 作为一种可选的实施方式,响应于向内容分发网络请求在第一类型页面上加载网络资源失败,向内容分发网络对应的本站请求在第一类型页面上加载网络资源,且向数据文件添加标识信息,包括:响应于向内容分发网络请求在第一类型页面上加载网络资源失败,触发第一类型页面中资源标签的异常事件;响应于异常事件,向本站请求在第一类型页面上加载网络资源,且向数据文件添加标识信息。
[0167] 在该实施例中,在向CDN在第一类型页面上加载网络资源失败的情况下,可以触发第一类型页面中资源标签的异常事件。当触发异常事件时,可以向本站请求在第一类型页面上加载网络资源,且向数据文件添加标识信息。
[0168] 可选地,上述实施例深入地描述了客户端如何在CDN资源加载失败时,触发异常事件,进而从本地服务器加载资源,并更新标识信息以反映其CDN访问状态的变化。
[0169] 可选地,当客户端接收到的第一类型页面(设计为从CDN加载资源)中的某个资源加载失败时,例如,JavaScript文件、CSS样式表或图片文件,浏览器会触发该资源标签(如`<script>`、`<link>`或``)的`onerror`事件。触发`onerror`事件后,客户端将执行预先设置的事件处理函数,该函数包含了从本地服务器请求资源和更新标识信息的逻辑。
[0170] 举例而言,在`onerror`事件处理函数中,客户端可以创建一个新的资源加载请求,但这次请求的目标不再是CDN,而是本地服务器。这通常涉及到动态生成一个新的资源标签,如`<script>`、`<link>`或``,并将这些标签的`src`或`href`属性设置为本地服务器上的资源路径。动态生成和添加资源标签的过程需要确保资源能够正确地融入页面布局和功能中,避免页面渲染或脚本执行的错误。客户端脚本应具备资源路径映射、标签创建和DOM操作的能力,以实现这一过程。
[0171] 除了重新加载资源外,触发`onerror`事件的另一个重要任务是更新客户端存储的数据文件(如Cookie)中的标识信息。标识信息应包含一个键值对,以反映客户端禁止访问CDN资源的状态。例如,可以设置`CDN_Access_Status`键,其值设置为`false`或`denied`。
[0172] 更新标识信息的目的是为了通知服务器客户端的CDN访问状态,使得服务器在后续的页面访问请求中能够根据这一状态做出适当的响应,如优先返回第二类型页面(设计为使用本地资源的页面)。
[0173] 作为一种可选的实施方式,该方法还包括:获取由插件或脚本生成的第一类型页面。
[0174] 在该实施例中,还可以获取由插件或脚本生成的第一类型页面。
[0175] 可选地,获取由插件或脚本生成的第一类型页面,是实现自适应前端资源加载的关键步骤之一。上述方法不仅确保了页面能够在多变的网络环境下高效加载,还为自动化实施提供了可能,减少了手动代码修改的工作量。
[0176] 可选地,插件或脚本在此处扮演着自动化工具的角色,能够扫描和分析现有的前端代码,识别出所有需要从CDN加载的资源(如CSS样式表、图片等),并自动创建两套资源引用:一套指向CDN,用于正常网络状况下的资源加载;另一套指向本地服务器,用作网络不稳定或CDN访问受限时的备用资源。
[0177] 可选地,插件或脚本还负责为资源加载标签(如`<script>`、`<link>`和``)添加错误事件处理器(`onerror`事件处理器),确保当CDN资源加载失败时,能够自动触发从本地服务器加载资源的逻辑,并更新标识信息。其中,`onerror`为一个事件属性,用于当页面或脚本发生错误时执行特定的处理函数。该事件属性可以附加到多种HTML元素上,如、<script>、<iframe>等,用于处理这些元素加载或执行时可能遇到的错误。
[0178] 可选地,在自适应加载方案中,插件或脚本将自动修改这些页面的资源引用,使其既有指向CDN的资源链接,也有指向本地服务器的备用链接。此外,页面代码中还将添加异常事件处理逻辑,用于在资源加载失败时重新从本地服务器加载资源,并更新客户端存储的数据文件(如Cookie)中的标识信息。
[0179] 可选地,插件或脚本会自动扫描页面代码,识别出所有的资源加载标签。对于每个资源加载标签,插件或脚本将生成一个指向本地服务器的备用资源引用,通常是在`onerror`事件处理器中动态生成。为每个资源加载标签添加`onerror`事件处理器,该处理器将在资源加载失败时触发备用资源的加载,并更新标识信息。确保本地服务器上存储的备用资源与CDN上的资源保持一致,以避免资源版本不匹配的问题。
[0180] 可选地,当用户访问网站时,客户端(通常是Web浏览器)将请求第一类型页面,这些页面已经被插件或脚本修改以支持自适应资源加载。页面加载时,将可以从CDN加载资源,如果CDN资源加载失败,`onerror`事件处理器将被触发,执行备用资源加载逻辑,并更新标识信息。
[0181] 可选地,通过插件或脚本自动生成第一类型页面,不仅减少了手动修改代码的工作量,还提高了代码的一致性和正确性。这一自动化流程可以集成到开发团队的构建和部署流水线中,确保每次代码更新时,自适应加载方案都能够正确实施。
[0182] 作为一种可选的实施方式,该方法还包括:响应于在第二类型页面上完成加载内容分发网络对应的本站的网络资源,且检测到允许客户端访问内容分发网络,向数据文件添加标识信息,其中,网络资源允许由本站缓存至内容分发网络上,标识信息用于表示允许客户端访问内容分发网络。
[0183] 在该实施例中,当在第二类型页面上完成加载CDN对应的本站的网络资源,且检测到允许客户端访问CDN,向数据文件添加标识信息。其中,网络资源可以为允许由本站缓存至CDN上。标识信息用于表示允许客户端访问CDN。
[0184] 可选地,上述实施方式可以在特定条件下,如何更新客户端的标识信息以反映其CDN访问能力的变化。特别是在客户端成功从本地服务器加载资源,并检测到其能够访问CDN资源的情况下,将标识信息更新为允许访问CDN,从而调整后续的资源加载策略。
[0185] 可选地,第二类型页面是指那些在设计时假设客户端无法访问CDN资源,因此所有资源都从本地服务器加载的页面。在客户端首次访问或在网络不稳定的情况下,这些页面能够提供基本功能和内容,避免用户因为资源加载失败而无法使用网站或应用。当第二类型页面上的资源从本地服务器成功加载并完成页面渲染后,客户端需要进一步检测其CDN访问能力,以确定是否可以将标识信息更新为允许访问CDN。
[0186] 可选地,检测CDN访问能力的逻辑可以内嵌在第二类型页面的客户端脚本中,通常是在页面资源完全加载后异步执行。检测过程可能涉及向CDN服务器发送一个小型的测试请求,如请求一个静态的文本文件或小图片,以验证客户端与CDN之间的网络连接是否畅通。
[0187] 可选地,一旦检测到客户端能够成功访问CDN资源,客户端脚本将向数据文件(比如,Cookie)中添加或更新标识信息,以表示客户端允许访问CDN。这一标识信息对于后续的页面访问请求奠定基础,将影响服务器选择返回第一类型页面还是继续返回第二类型页面。标识信息的更新应确保其持久性,即即使用户关闭浏览器窗口或标签页,这一信息仍能保存在客户端设备上,使得服务器在用户重新访问时能够读取这一状态。
[0188] 作为一种可选的实施方式,响应于在第二类型页面上完成加载内容分发网络对应的本站的网络资源,且检测到允许客户端访问内容分发网络,向数据文件添加标识信息,包括:从第二类型页面中识别出资源标签,其中,资源标签中包括本站的本站地址;响应于在第二类型页面上,完成加载资源标签中本站地址上的网络资源,且检测到允许客户端访问内容分发网络,利用第二类型页面触发向数据文件添加标识信息。
[0189] 在该实施例中,在第二类型页面上完成加载CDN对应的本站的网络资源,且检测到允许客户端访问CDN,向数据文件添加标识信息的过程中,可以从第二类型页面中识别出资源标签,在第二类型页面上,可以完成加载资源标签中本站地址上的网络资源。且可以检测到允许客户端访问CDN,利用第二类型页面触发向数据文件添加标识信息。其中,资源标签中可以包括本站的本站地址。
[0190] 可选地,上述方法详细阐述了如何在客户端成功从本地服务器加载资源并检测到能够访问CDN时,利用第二类型页面的特性来更新客户端数据文件中的标识信息,以反映其CDN访问能力的变化。这一过程对于动态调整资源加载策略,提供合适的用户体验。以下是上述步骤的详细分析:
[0191] 可选地,第二类型页面设计为仅从本地服务器加载资源,以应对CDN不可访问的情况。在这一页面上,客户端(例如Web浏览器)需要能够识别出所有资源加载标签,如``、`<script>`、`<link>`等,其中这些标签的`src`或`href`属性指向本地服务器的资源地址。上述识别过程通常通过客户端脚本来实现,可以使用DOM遍历和选择器来定位页面中的资源加载标签,并获取对应的资源地址。
[0192] 可选地,在识别出所有资源标签后,客户端将开始加载这些标签指向的本地服务器上的网络资源。上述过程与常规的页面加载流程相似,但更关注资源的加载状态,确保所有资源都成功加载到页面中,以完成页面的完整渲染。
[0193] 可选地,一旦第二类型页面上的所有本地资源加载完成,客户端需要进行一次CDN访问能力的检测。这通常涉及向CDN服务器发送一个小型的测试请求,如请求一个很小的图片或文本文件。如果请求成功,且响应时间在可接受范围内,可以认为客户端能够访问CDN资源。检测逻辑应具备错误处理和超时机制,以避免因网络瞬时波动而导致的误判。同时,为了提高检测的准确性和效率,测试请求应设计为低带宽消耗,最小化对网络资源的影响。
[0194] 可选地,当客户端成功检测到能够访问CDN资源后,接下来的步骤是向数据文件(如Cookie或localStorage)中添加或更新标识信息。这一信息将用于指示客户端允许访问CDN,从而影响后续页面的资源加载策略。客户端脚本(比如,JavaScript)可以负责执行这一更新操作,通过调用相应的应用程序编程接口(Application Programming Interface,简称为API)的读取和设置cookie的简单接口(`document.cookie`)等来修改存储在客户端设备上的标识信息。
[0195] 作为一种可选的实施方式,该方法还包括:获取由插件或脚本生成的第二类型页面。
[0196] 在该实施例中,可以获取由插件或脚本所生成的第二类型页面。
[0197] 可选地,获取由插件或脚本生成的第二类型页面是一个重要的环节,确保了在CDN资源不可用或客户端访问CDN受限的情况下,页面资源仍能从本地服务器加载,从而维持网页的正常功能和用户体验。
[0198] 可选地,插件或脚本在本申请实施例中担当着自动化工具的角色,用于分析和修改现有前端代码,生成第一类型页面和第二类型页面。第一类型页面设计为优先从CDN加载资源,而第二类型页面则用于在CDN资源加载失败的情况中从本地服务器加载所有资源。
[0199] 可选地,生成第二类型页面的过程涉及对原页面代码的深度分析,识别所有资源加载标签,如``、`<script>`、`<link>`等,然后将上述标签指向的资源地址从CDN地址调整为本地服务器地址。此外,脚本或插件还负责在第二类型页面中添加必要的检测逻辑和标识信息更新机制,以确保客户端能够根据CDN访问能力的变化,动态调整资源加载策略。
[0200] 可选地,第二类型页面主要用于处理以下场景:当客户端首次访问网站时,由于未知的网络条件,可能直接加载第二类型页面,以确保所有资源都能从本地服务器获取,避免CDN访问失败导致页面加载不完全。如果客户端在访问第一类型页面时遇到CDN资源加载失败,页面访问拦截器将根据Cookie中的CDN访问状态标识,重定向用户到第二类型页面,以确保资源的正常加载。
[0201] 可选地,当获取到第二类型页面时,客户端将从本地服务器加载所有资源。这一过程在页面加载初期即开始,确保页面能够快速显示给用户,即使在CDN资源不可访问的情况下,用户仍然能够正常使用网站或应用。与此同时,为了提高后续加载效率和提供更优的用户体验,第二类型页面中还包含了检测CDN访问能力的逻辑。一旦检测到客户端能够成功访问CDN,页面将触发标识信息的更新,向数据文件(如Cookie)中添加能够访问CDN的标识,从而在后续的页面访问中,页面访问拦截器将根据这一标识信息优先返回第一类型页面,实现资源加载策略的自适应调整。
[0202] 本申请实施例从服务器侧,还提供了一种网络资源的加载方法,图4是根据本申请实施例的另一种网络资源的加载方法的流程图,如图4所示,该方法应用于服务器,服务器上安装有插件,服务器用于调用插件以执行以下方法:
[0203] 步骤S402,获取客户端的页面访问请求,其中,页面访问请求用于向服务器请求访问页面。
[0204] 在本申请上述步骤S402提供的技术方案中,获取客户端的页面访问请求,是服务器端处理前端资源自适应加载方案中的一个关键环节。上述方法可以通过服务器接收来自客户端的页面访问请求(HTTP请求),该请求旨在获取特定的网页或资源。
[0205] 可选地,当用户在浏览器中输入URL或通过点击链接等方式发起访问某个页面的请求时,浏览器会向服务器发送一个HTTP请求。这个请求包含了访问页面的URL、请求类型、用户代理信息(即浏览器和操作系统等信息)、请求头等信息。在服务器接收到客户端的HTTP请求后,会解析请求中包含的信息,以确定用户请求的具体内容。服务器根据请求的URL、请求类型等信息,确定应提供哪个页面或资源文件。
[0206] 可选地,服务器上安装有插件,这个插件的作用是在服务器接收到页面访问请求后,能够根据客户端的状态(如是否能够访问CDN资源的标识存储在客户端的Cookie或localStorage中)来决定如何响应请求。该插件可以是服务器端的脚本或模块,它在接收到请求时运行,根据客户端提供的信息决定是否返回一个包含自适应加载逻辑的页面版本,或者直接返回一个使用本地资源的页面版本。也即,通过上述插件执行,使得服务器具备前端资源自适应加载的能力。
[0207] 步骤S404,响应于页面访问请求,从页面访问请求中识别出标识信息,其中,标识信息用于表示客户端对内容分发网络进行访问的权限。
[0208] 在本申请上述步骤S404提供的技术方案中,在服务器获取到客户端的页面访问请求之后,可以对页面访问请求进行识别,确定发出该页面访问请求的客户端是否有对CDN进行访问的权限,也即,可以从页面访问请求中识别出用来判断是否有对相应的CDN进行访问的权限的标识信息。
[0209] 可选地,从客户端发送的页面访问请求中提取特定的标识信息,上述标识信息用于判断客户端是否具有访问CDN资源的权限。
[0210] 步骤S406,确定与标识信息相匹配的至少一目标页面,以及与标识信息相匹配的网络资源,其中,目标页面的页面类型与标识信息对应的权限相对应,网络资源的来源与标识信息对应的权限相对应。
[0211] 在本申请上述步骤S406提供的技术方案中,在从页面访问请求中识别出标识信息之后,可以确定出与标识信息相匹配的目标页面,也可以确定出与标识信息相匹配的网络资源(资源)。
[0212] 可选地,从页面访问请求中所识别出的标识信息,选择合适的资源加载路径,并按照资源加载路径,决定返回哪种类型的目标页面以及相应的网络资源加载策略。也即,按照相应的资源加载路径,去调用相应类型的目标网页,并按照相应的网络资源加载策略,对该目标网页上的网页资源进行加载。若资源加载路径为CDN,则可以从CDN中获取相应目标网页中的前端资源,反之,若资源加载路径为本站,则可以从本站中获取相应目标网页中的前端资源。
[0213] 步骤S408,将目标页面返回至客户端,且向目标页面加载网络资源。
[0214] 在本申请上述步骤S408提供的技术方案中,在确定出与标识信息相匹配的目标页面,以及标识信息相匹配的网络资源之后,可以将目标页面返回至客户端,并可以在客户端上的目标页面上加载网络资源。
[0215] 可选地,将服务器根据标识信息所选择的目标页面以及相应的网络资源,返回给客户端,确保客户端能够根据客户端对CDN进行访问的权限加载正确的资源。服务器在确定了与标识信息相匹配的目标页面后,可以构建一个包含该页面内容的响应。响应中会包含所有必要的资源引用,上述资源引用根据标识信息指向CDN资源或本地资源。响应的内容类型可以与客户端请求的目标页面的页面类型相匹配。
[0216] 可选地,插件能够根据客户端提供的标识信息,判断客户端是否能够访问CDN。如果客户端可以访问CDN,插件将返回使用CDN资源的页面;如果客户端无法访问CDN,插件将返回使用本地资源的页面。这种自适应策略避免了资源加载失败或加载时间过长的问题,保证了页面在任何网络环境下都能迅速加载,显著增强了网页的稳定性和响应速度。通过插件,服务器端的资源加载策略调整完全自动化,无需人工干预。这意味着每当有客户端请求页面时,插件都会自动执行上述流程,根据最新的网络状况和客户端状态提供合适的页面和资源加载方案。自动化处理不仅减少了开发和运维工作量,避免了人为错误,还能够动态适应网络环境的变化,确保服务的持续可用性和高效性。通过插件的智能判断,可以合理分配资源的使用。在客户端能够访问CDN的情况下,优先使用CDN资源,这可以有效分发服务器的负载,减轻服务器带宽压力;而在客户端无法访问CDN的情况下,使用本地资源,虽然可能增加了服务器的存储压力,但避免了外部网络延迟或连接问题带来的资源加载失败,保证了用户体验。
[0217] 可选地,插件通过读取客户端的标识信息来确定资源加载策略,而这些标识信息可以存储在Cookie或localStorage中,这允许服务器在不获取用户详细网络信息的情况下做出决策。同时,本地资源的加载减少了对第三方CDN的依赖,降低了由CDN引入的安全风险,如中间人攻击或资源被篡改的风险。插件的设计允许开发者容易地根据新的网络需求或技术变化进行调整和扩展。例如,如果以后引入了新的资源加载策略,如从本地缓存加载或使用其他CDN服务,插件可以被更新或替换,而不需要对核心服务器代码进行修改。这种技术灵活性使得方案能够适应不断变化的网络环境和用户需求。
[0218] 通过本申请上述步骤S402至步骤S408,通过在服务器端部署插件,本申请实施例能够智能、自动地根据客户端的网络状况自适应调整资源加载策略,提高了网页加载速度,优化了资源使用效率,增强了用户隐私和安全性,同时也保持了良好的技术灵活性和扩展性,是一个高效、稳定、安全的网络资源加载解决方案,从而实现了提高网络资源的加载效率的技术效果,解决了网络资源的加载效率低的技术问题。
[0219] 根据本申请实施例,还提供了一种网络资源的加载系统的实施例,图5是根据本申请实施例的一种网络资源的加载系统的示意图,如图5所示,网络资源的加载系统500部署于公共网络或专有网络中,且网络资源的加载系统500可以包括:客户端501和服务器502。
[0220] 客户端501,用于向服务器发送页面访问请求,其中,页面访问请求用于向服务器请求访问页面。
[0221] 服务器502,用于响应于页面访问请求,从页面访问请求中识别出标识信息,其中,标识信息用于表示客户端对内容分发网络进行访问的权限;确定与标识信息相匹配的至少一目标页面,以及与标识信息相匹配的网络资源,其中,目标页面的页面类型与标识信息对应的权限相对应,网络资源的来源与标识信息对应的权限相对应;其中,客户端用于加载服务器返回的目标页面,且在目标页面上加载网络资源。
[0222] 在该实施例中,提供了一种网络资源的加载系统。通过客户端501向服务器发送页面访问请求;通过服务器502响应于页面访问请求,从页面访问请求中识别出标识信息;确定与标识信息相匹配的至少一目标页面,以及与标识信息相匹配的网络资源;其中,通过客户端501加载服务器返回的目标页面,且在目标页面上加载网络资源,从而实现了提高网络资源的加载效率的技术效果,解决了网络资源的加载效率的技术问题。
[0223] 需要说明的是,本申请中所涉及的用户信息(包括但不限于用户设备信息、用户个人信息等)和数据(包括但不限于用于分析的数据、存储的数据、展示的数据等),比如,对进行检验的数据,均为经用户授权或者经过各方充分授权的信息和数据,并且相关数据的收集、使用和处理需要遵守相关国家和地区的相关法律法规和标准,并提供有相应的操作入口,供用户选择授权或者拒绝。
[0224] 目前,基于公共网络(如互联网)的网站或者软件,为了降低前端资源加载的耗时,通常的做法是将前端资源存放到CDN上,当用户访问网页时,通过CDN域名就近加载前端资源。在专有网络中,能否访问CDN域名往往是未知的,上述基于公共网络的网站或者软件,如果直接部署到专有网络中,就可能因为无法加载CDN上的前端资源,导致网站或者软件不可用。
[0225] 在一种相关技术中,在部署到专有网络时,不管能不能访问CDN域名,手工或者使用脚本从CDN上下载所有需要的前端资源,将这些前端资源托管到专有网络中的服务器上,修改代码或者配置,将CDN域名切换为专有网络中的域名。然而,上述方法存在如下缺点:每次部署、更新都需要人工介入,费时费力,容易出错。如果该专有网络能访问CDN域名,前端资源仍通过专有网络加载,无疑会对带宽资源形成了较大浪费。
[0226] 在另一种相关技术中,在部署到专有网络时,和网络管理员确认是否能访问CDN域名,如果能访问,则可以直接部署,否则按照上述相关技术中的方法进行部署。然而,上述方法存在如下缺点:由于专有网络存在安全策略调整、硬件升级、软件升级等不可预知的操作,无法保证CDN域名永远都可以访问,在无法访问时,就会导致整个网站或者软件不可用。
[0227] 在另一种相关技术中,图6是一种相关技术中的前端资源的加载方法的示意图,如图6所示,在开发网站或者软件时,在代码中冗余CDN上的前端资源,修改代码中的所有前端页面,为页面中所有资源加载标签添加onError事件,包括但不限于:<link>,<image>,<script>等。在页面中增加处理onError事件的响应代码,在加载CDN域名上的前端资源失败时,通过代码动态创建新的资源加载标签,将新标签中的资源地址域名指向当前网站或者软件的域名,使用代码中冗余的前端资源,重新加载一次。上述方法存在如下缺点:在CDN域名无法访问时,请求CDN域名的响应时间往往是几十秒乃至数分钟,用户每次访问页面都需要等待非常久,对于用户体验存在较大的影响。
[0228] 然而,上述三种方法仍存在网络资源的加载效率低的技术问题。
[0229] 进一步地,本申请实施例提供了一种专有网络下前端资源自适应加载方案方法,若需要对网络资源进行加载,则可以实时监测客户端是否具有访问某一页面(也即,前端页面)的请求,也即,页面访问请求。若监测到页面访问请求,可以从其中分析出该客户端是否有对CDN进行访问的权限对应的标识信息。若访问请求中没有上述标识信息,则无法对该页面中的网络资源进行加载,反之,则可以确定出与标识信息中的权限所匹配的可访问的至少一目标页面。并可以将该目标页面返回至相应的客户端,并在客户端上对该目标页面上的网络资源进行加载。在该实施例中,提出了一种前端资源自适应加载方法,其核心在于能够根据页面访问请求中所包含的标识信息自动判断客户端是否具备访问CDN资源的权限,并据此返回合适的页面版本,从而在无需人工介入的情况下,实现资源的高效、智能加载。上述方法在公有云和专有云环境下均能保持良好的适应性和性能,从而实现了提高网络资源的加载效率的技术效果,解决了网络资源的加载效率低的技术问题。
[0230] 下面对该实施例的上述方法进行进一步的介绍。
[0231] 在本申请实施例中,图7是根据本申请实施例的一种专有网络下前端资源自适应加载方法的流程图,如图7所示,针对方案中的自适应选择从CDN加载资源还是从本站加载资源,可以通过以下方式实现:在页面加载时,通过检测网络情况,可以判断当前用户所处的网络环境是否能够访问CDN域名。这可以通过发送简单的网络请求来检测CDN域名的可访问性,或者通过测量网络延迟等指标来判断网络状况。根据网络情况的检测结果,动态决定从CDN加载资源还是从本站加载资源。如果网络环境能够访问CDN域名,则优先选择从CDN加载资源,以提高加载速度和性能;如果无法访问CDN域名,则切换到从本站加载资源,确保资源能够正常加载。在代码中设置备用资源加载策略。当检测到无法访问CDN域名时,可以自动切换为加载本站的备用资源,保证页面的正常展示和功能运行。在本站服务器上缓存一份前端资源的副本,以备CDN资源无法访问时使用。通过本地资源缓存,可以确保即使无法访问CDN,也能够提供稳定的资源加载。建立检测系统,实时监测CDN域名的可用性。一旦检测到CDN域名无法访问,可以触发报警机制,及时通知相关人员进行处理,以降低对用户体验的影响。
[0232] 通过上述自适应选择加载资源的方式,可以根据实际的网络情况动态调整资源加载策略,提高系统的稳定性和用户体验。确保在网络环境变化或CDN域名无法访问时,仍能够保证页面的正常加载和功能运行。这种自适应加载资源的方式能够有效应对不同网络环境下的资源加载需求,提升网站的可用性和性能。
[0233] 在该实施例中,可以对页面做相应修改,新增以下两个逻辑:1.CDN资源加载失败后,重新从本站加载资源。2.CDN资源加载失败后,在Cookie中添加CDN域名无法访问的标识。
[0234] 可选地,对于资源加载失败后执行获取加载失败的资源标签、创建新的资源标签并设置资源路径、将新标签添加到页面上、以及在cookie中添加CDN域名无法访问的标识,
[0235] 举例而言,当资源加载失败时,可以通过JavaScript代码在资源加载标签的onError事件中捕获加载失败的事件。可以使用event.target来获取触发事件的资源标签,从而识别加载失败的资源。在资源加载失败后,可以动态创建新的资源加载标签,例如,在网页的DOM中动态创建新的HTML元素(标签元素)(也即,使用document.createElement()方法)。将新标签的src或者href属性设置为代码中冗余的资源路径,以确保能够加载本地资源。将新创建的资源标签添加到页面上,可以使用将一个节点添加到另一个节点的子节点列表的末尾(也即,document.appendChild()方法),来将新创建的资源标签添加到页面的特定位置,使其开始加载冗余资源。在资源加载失败时,可以通过JavaScript代码在cookie中添加一个标识来表示CDN域名无法访问的情况。这可以通过document.cookie属性来设置cookie,添加一个特定的键值对,如CDN当前不可用或无法访问的标志("CDNUnavailable=true"),以便后续根据这个标识进行相应的处理。
[0236] 通过上述操作,可以实现在资源加载失败后动态切换到本地资源加载的逻辑,并在cookie中记录CDN域名无法访问的标识。这样的处理方式可以有效应对CDN资源加载失败的情况,保证页面的正常展示和功能运行,提高系统的稳定性和用户体验。同时,确保网站在各种网络环境下都能够正常运行,并及时处理资源加载失败的情况。
[0237] 在该实施例中,原页面通过,<link>,<script>标签从CDN加载3个资源,修改后的页面为每个资源标签添加了onError事件,并在页面中增加onError事件的响应代码,在代码中实现了上述的两个逻辑。
[0238] 图8是根据本申请实施例的一种修改后页面在浏览器中运行时前端资源的加载逻辑的示意图,如图8所示,该过程可以包括如下步骤:
[0239] 步骤S801,获取前端资源,也即,普通页面可以从CDN获取前端资源,CDN可以将相应的前端资源返回至普通页面进行加载。然而,若CDN资源获取失败,则可以执行步骤S802来获取前端资源,也即,可以从本站中获取前端资源。本站可以将相应的前端资源返回至普通页面进行加载。在对从本站资源中所获取的前端资源加载完成之后,还可以执行步骤S803,在cookie中添加CDN域名无法访问的标识。
[0240] 在该实施例中,新增了使用本站资源的页面,该页面上的前端资源全部通过本站加载。在页面加载完成后,异步检测CDN域名是否可以访问,如果可以访问,则在Cookie中添加CDN域名可以访问的标识。
[0241] 可选地,在上述使用本站资源的页面中,前端资源(如图片、样式表、脚本等)都通过本站加载,不依赖外部CDN或其他第三方服务提供的资源。这样可以确保页面的资源完全来自本站,避免了CDN资源加载失败的可能性。页面加载完成后,通过异步请求方式检测CDN域名是否可以访问。可以通过发送一个简单的网络请求到CDN域名,然后根据返回的结果判断CDN域名的访问情况。如果可以正常访问,即CDN域名可用。如果异步检测发现CDN域名可以访问,就在Cookie中添加一个标识,表示CDN域名可以访问。这个标识可以是一个特定的键值对,如客户端能够成功访问CDN("CDNAvailable=true")。这样在后续的页面加载过程中,可以根据这个标识动态调整资源加载策略,确保页面的正常加载。
[0242] 在本申请实施例中,通过上述方法,可以在使用本站资源的页面中实现了在页面加载完成后异步检测CDN域名的访问情况,以及在Cookie中添加CDN域名可访问的标识。这样的做法可以确保在CDN域名可用时,能够灵活地根据实际情况调整资源加载策略,提高页面加载速度和性能。
[0243] 举例而言,在页面加载后执行异步请求原始页面中前端资源的CDN域名,并在请求成功时在cookie中添加CDN域名可以访问的标识的流程,具体分析如下:页面加载完成后,通过异步请求的方式向原始页面中的前端资源CDN域名发送网络请求。向CDN域名发送请求,检测CDN域名的可访问性。在异步请求的回调函数中,根据请求的返回结果判断CDN域名的可访问性。如果请求成功并返回正确的响应,则表示CDN域名可以访问;如果请求失败或返回错误信息,则表示CDN域名无法访问。当异步请求成功且CDN域名可以访问时,在cookie中添加一个特定的标识,表示CDN域名可以访问。这可以通过JavaScript中Document.cookie属性来设置cookie,添加一个键值对,如"CDNAvailable=true”。通过上述流程,实现了在页面加载后异步请求原始页面中前端资源的CDN域名,以及在请求成功时在cookie中添加CDN域名可以访问的标识。
[0244] 可选地,在使用本站资源的页面中,将原本从CDN加载的资源地址调整为本站地址。这样页面的所有前端资源都将通过本站加载,不再依赖外部CDN资源。页面加载完成后,异步进行CDN域名的检测。通过发送一个简单的网络请求到CDN域名,检测CDN域名的访问情况。如果检测成功,即CDN域名可访问,继续执行后续逻辑;如果检测失败,表示CDN域名无法访问,执行相应的处理。当CDN域名检测失败时,在Cookie中添加一个特定的标识,如"CDNUnavailable=true”。这个标识表示CDN域名无法访问的情况,可以在后续的页面加载过程中根据这个标识进行相应的资源加载策略调整。通过将资源地址调整为本站地址,确保页面的所有资源都来自本站,避免了CDN资源加载失败的可能性,提高了页面的稳定性。通过CDN域名检测和在Cookie中添加标识的逻辑,实现了根据CDN域名访问情况动态调整资源加载策略,提高了系统的智能性和适应性。
[0245] 图9是根据本申请实施例的一种使用本站资源的页面在浏览器中运行时前端资源的加载逻辑的示意图,如图9所示,该过程可以执行如下步骤:使用本站资源的页面在浏览器中运行时,可以执行步骤S901,获取前端资源,也即,可以通过本站资源中获取相应的前端资源,本站资源可以将相应的前端资源返回至使用本站资源的页面,进行加载。若页面加载完成之后,还可以执行步骤S902,异步检测CDN域名是否可访问,也即,可以向CDN资源异步检测CDN域名是否可访问。若CDN可以访问,可以执行步骤S903,可以在cookie中添加CDCN域名可以访问的标识。
[0246] 在该实施例中,可以在网站或者软件实例中新增页面访问拦截器,新增一个页面访问拦截器,该拦截器可以在每次页面访问请求到达服务器时进行拦截处理。拦截器需要获取请求中的Cookie信息,判断其中是否携带了CDN域名是否可访问的标志。如果Cookie中包含了CDN域名可访问的标志,说明该页面可以使用CDN提供的资源,可以直接返回普通页面。如果Cookie中不包含CDN域名可访问的标志,说明该页面仅能使用本站资源,需要返回使用本站资源的页面。拦截器可以在判断完Cookie信息后,根据具体情况进行页面的重定向或拒绝访问等操作。通过新增页面访问拦截器,可以实现对页面访问的控制和管理,确保页面资源的安全可靠性。
[0247] 图10是根据本申请实施例的一种新增页面访问的拦截器的示意图,如图10所示,新增一个页面访问的拦截器,所有的页面访问的请求都需要经过该拦截器,拦截器收到页面访问请求后,根据Cookie中的携带的CDN域名是否可访问的标志来判断返回使用本站资源的页面还是普通页面。
[0248] 在该实施例中,可以手动实施,但是因为涉及的代码改动比较多,手动实施的成本较高,并且在开发阶段,开发人员并不需要感知到该方案的实施,所以需要一种自动化实施的插件或者脚本,让一份普通的代码在经过该插件或脚本执行后,自动具备前端资源自适应加载的能力。本方案中配套设计了一种自动化实施的插件或脚本。
[0249] 图11是根据本申请实施例的一种自动化实施的专有网络下前端资源自适应加载方法的流程图,如图11所示,该方法可以包括如下步骤:
[0250] 步骤S1101,扫描代码中的各个前端页面。
[0251] 在该实施例中,通过扫描代码中各个前端页面,可以定位和识别所有包含前端资源加载指令的页面代码。自动化工具(如插件或脚本)将遍历项目中的所有HTML文件、JavaScript文件等,找到那些可能需要从CDN加载资源的前端页面。
[0252] 可选地,自动化工具可以使用正则表达式、DOM解析器或其他代码解析技术,来识别和定位资源加载标签,如、<script>、<link>等。上述过程可能涉及递归遍历项目目录结构,以确保所有页面代码都被检查,包括那些可能位于子目录或动态生成的页面。
[0253] 步骤S1102,遍历各个页面中的资源标签。
[0254] 在该实施例中,在识别了所有前端页面后,自动化工具将进一步遍历这些页面中的资源加载标签,以提取和分析资源加载指令。
[0255] 可选地,工具将识别出所有资源加载标签,包括图片、JavaScript脚本、CSS样式表等的加载指令。从资源加载标签中提取出资源的URL,特别是那些指向CDN的资源地址,为后续步骤做准备。
[0256] 步骤S1103,获取资源标签中的CDN地址。
[0257] 在该实施例中,自动化工具将专注于提取那些指向CDN的资源地址,这些地址将用于后续的资源下载和备份资源生成。
[0258] 可选地,工具将检查资源URL,确认哪些资源是通过CDN进行分发的。自动化工具将构建一份包含所有CDN资源地址的列表,用于后续的资源下载操作。
[0259] 步骤S1104,下载CDN地址上的资源到本地代码目录中。
[0260] 在该实施例中,自动化工具将根据上述过程中提取的CDN资源地址列表,下载这些资源到本地代码目录,作为备用资源或用于后续生成第二类型页面。
[0261] 可选地,自动化工具将使用异步网络请求方法,从CDN下载资源到本地。在下载资源时,自动化工具还应处理资源的缓存和版本控制问题,以保证本地资源与CDN资源的一致性。
[0262] 步骤S1105,修改各个页面,为每个页面的资源标签增加onerror事件,为各个页面追加响应error事件的代码。
[0263] 在该实施例中,在资源下载到本地后,自动化工具将修改所有前端页面的代码,为资源加载标签添加onerror事件处理器,一旦CDN资源加载失败,将触发备用资源加载逻辑,并更新标识信息。
[0264] 可选地,工具将在每个资源加载标签上添加onerror事件,该事件将处理CDN资源加载失败的情况。工具还将为页面追加响应error事件的代码,这些代码将负责在CDN资源加载失败时,加载本地资源,并更新客户端标识信息,如Cookie,以反映CDN访问状态。
[0265] 步骤S1106,为各个页面生成使用本站资源的页面。
[0266] 在该实施例中,自动化工具将为每个页面生成一个第二类型页面(使用本站资源的页面),上述页面的资源全部通过本地服务器加载。
[0267] 可选地,工具将基于原页面代码,生成对应的第二类型页面,其中所有资源加载指令都指向本地服务器。工具将修改资源加载标签中的src或href属性,将其指向本地服务器上的资源。
[0268] 步骤S1107,生成页面访问拦截器。
[0269] 在该实施例中,自动化工具将生成一个页面访问拦截器,用于根据客户端标识信息(如Cookie中CDN访问状态)来决定返回第一类型页面还是第二类型页面。
[0270] 可选地,拦截器将接收所有页面访问的请求,并分析客户端标识信息。如果标识信息表明客户端可以访问CDN,拦截器将返回第一类型页面;否则,将返回第二类型页面,确保资源从本地服务器加载。拦截器还应具备解析客户端标识信息的能力,用于判断客户端的CDN访问状态,并做出相应的页面类型选择。
[0271] 可选地,将上述插件或脚本集成到代码编译、打包的流水线中,在使用流水线对代码进行编译、打包时,就会自动为代码加上前端资源自适应加载的能力。
[0272] 在本申请实施例中,通过上述方法共同构成了一个自动化实施专有网络下前端资源自适应加载方法的流程,不仅能够确保资源在CDN不可访问时仍能加载,还能根据客户端的网络状态动态调整资源加载策略,提高用户体验。通过自动化工具的使用,显著减少了手动修改代码的工作量,提高了开发效率,同时确保了代码的一致性和正确性。
[0273] 本申请实施例中,若需要对网络资源进行加载,则可以实时监测客户端是否具有访问某一页面(也即,前端页面)的请求,也即,页面访问请求。若监测到页面访问请求,可以从其中分析出该客户端是否有对CDN进行访问的权限对应的标识信息。若访问请求中没有上述标识信息,则无法对该页面中的网络资源进行加载,反之,则可以确定出与标识信息中的权限所匹配的可访问的至少一目标页面。并可以将该目标页面返回至相应的客户端,并在客户端上对该目标页面上的网络资源进行加载。在该实施例中,提出了一种前端资源自适应加载方法,其核心在于能够根据页面访问请求中所包含的标识信息自动判断客户端是否具备访问CDN资源的权限,并据此返回合适的页面版本,从而在无需人工介入的情况下,实现资源的高效、智能加载。上述方法在公有云和专有云环境下均能保持良好的适应性和性能,从而实现了提高网络资源的加载效率的技术效果,解决了网络资源的加载效率低的技术问题。
[0274] 根据本申请实施例,还提供了一种用于实施上述图2所示的网络资源的加载方法的网络资源的加载装置。
[0275] 图12是根据本申请实施例的一种网络资源的加载装置的示意图,如图12所示,该网络资源的加载装置1200可以包括:第一获取单元1202、第一识别单元1204、第一确定单元1206和第一加载单元1208。
[0276] 第一获取单元1202,用于获取客户端的页面访问请求。
[0277] 第一识别单元1204,用于响应于页面访问请求,从页面访问请求中识别出标识信息。
[0278] 第一确定单元1206,用于确定与标识信息相匹配的至少一目标页面,以及与标识信息相匹配的网络资源。
[0279] 第一加载单元1208,用于将目标页面返回至客户端,且向目标页面加载网络资源。
[0280] 此处上述第一获取单元1202、第一识别单元1204、第一确定单元1206和第一加载单元1208对应于上述实施例中的步骤S202至步骤S208,四个单元与对应的步骤所实现的实例和应用场景相同,但不限于上述实施例所公开的内容。需要说明的是,上述单元可以是存储在存储器(例如,存储器1504)中并由一个或多个处理器(例如,处理器1502a,1502b……,1502n)处理的硬件组件或软件组件,上述单元也可以作为装置的一部分可以运行在下述实施例提供的计算机终端A中。
[0281] 根据本申请实施例,还提供了一种用于实施上述图3所示的网络资源的加载方法的网络资源的加载装置。
[0282] 图13是根据本申请实施例的一种网络资源的加载装置的示意图,如图13所示,该网络资源的加载装置1300可以包括:发送单元1302和第二加载单元1304。
[0283] 发送单元1302,用于向服务器发送页面访问请求。
[0284] 第二加载单元1304,用于加载服务器响应页面访问请求,而返回的至少一目标页面,且在目标页面上加载对应的网络资源。
[0285] 此处需要说明的是,上述发送单元1302和第二加载单元1304对应于上述实施例中的步骤S302至步骤S304,两个单元与对应的步骤所实现的实例和应用场景相同,但不限于上述实施例所公开的内容。需要说明的是,上述单元可以是存储在存储器(例如,存储器1504)中并由一个或多个处理器(例如,处理器1502a,1502b……,1502n)处理的硬件组件或软件组件,上述单元也可以作为装置的一部分可以运行在下述实施例提供的计算机终端A中。
[0286] 根据本申请实施例,还提供了一种用于实施上述图4所示的网络资源的加载方法的网络资源的加载装置。
[0287] 图14是根据本申请实施例的一种网络资源的加载装置的示意图,如图14所示,该网络资源的加载装置1400可以包括:第二获取单元1402、第二识别单元1404、第二确定单元1406和第三加载单元1408。
[0288] 第二获取单元1402,用于获取客户端的页面访问请求。
[0289] 第二识别单元1404,用于响应于页面访问请求,从页面访问请求中识别出标识信息。
[0290] 第二确定单元1406,用于确定与标识信息相匹配的至少一目标页面,以及与标识信息相匹配的网络资源。
[0291] 第三加载单元1408,用于将目标页面返回至客户端,且向目标页面加载网络资源。
[0292] 此处上述第二获取单元1402、第二识别单元1404、第二确定单元1406和第三加载单元1408对应于上述实施例中的步骤S402至步骤S408,四个单元与对应的步骤所实现的实例和应用场景相同,但不限于上述实施例所公开的内容。需要说明的是,上述单元可以是存储在存储器(例如,存储器1504)中并由一个或多个处理器(例如,处理器1502a,1502b……,1502n)处理的硬件组件或软件组件,上述单元也可以作为装置的一部分可以运行在下述实施例提供的计算机终端A中。
[0293] 在该网络资源的加载装置中,若需要对网络资源进行加载,则可以实时监测客户端是否具有访问某一页面(也即,前端页面)的请求,也即,页面访问请求。若监测到页面访问请求,可以从其中分析出该客户端是否有对CDN进行访问的权限对应的标识信息。若访问请求中没有上述标识信息,则无法对该页面中的网络资源进行加载,反之,则可以确定出与标识信息中的权限所匹配的可访问的至少一目标页面。并可以将该目标页面返回至相应的客户端,并在客户端上对该目标页面上的网络资源进行加载。在该实施例中,提出了一种前端资源自适应加载方法,其核心在于能够根据页面访问请求中所包含的标识信息自动判断客户端是否具备访问CDN资源的权限,并据此返回合适的页面版本,从而在无需人工介入的情况下,实现资源的高效、智能加载。上述方法在公有云和专有云环境下均能保持良好的适应性和性能,从而实现了提高网络资源的加载效率的技术效果,解决了网络资源的加载效率低的技术问题。
[0294] 本申请的实施例可以提供一种计算机终端,该计算机终端可以是计算机终端群中的任意一个计算机终端设备。可选地,在本实施例中,上述计算机终端也可以替换为移动终端等终端设备。
[0295] 可选地,在本实施例中,上述计算机终端可以位于计算机网络的多个网络设备中的至少一个网络设备。
[0296] 在本实施例中,上述计算机终端可以执行网络资源的加载方法中上述步骤的程序代码。
[0297] 可选地,图15是根据本申请实施例的一种计算机终端的结构框图。如图15所示,该计算机终端A可以包括:一个或多个(图中仅示出一个)处理器1502、存储器1504以及传输装置1506。
[0298] 其中,存储器可用于存储软件程序以及模块,如本申请实施例中的网络资源的加载方法和装置对应的程序指令 / 模块,处理器通过运行存储在存储器内的软件程序以及模块,从而执行各种功能应用以及数据处理,即实现上述的网络资源的加载方法。存储器可包括高速随机存储器,还可以包括非易失性存储器,如一个或者多个磁性存储装置、闪存、或者其它非易失性固态存储器。在一些实例中,存储器可进一步包括相对于处理器远程设置的存储器,上述远程存储器可以通过网络连接至计算机终端A。上述网络的实例包括但不限于互联网、企业内部网、局域网、移动通信网及其组合。
[0299] 采用本申请实施例,提供了一种网络资源的加载方法。在本申请实施例中,若需要对网络资源进行加载,则可以实时监测客户端是否具有访问某一页面(也即,前端页面)的请求,也即,页面访问请求。若监测到页面访问请求,可以从其中分析出该客户端是否有对CDN进行访问的权限对应的标识信息。若访问请求中没有上述标识信息,则无法对该页面中的网络资源进行加载,反之,则可以确定出与标识信息中的权限所匹配的可访问的至少一目标页面。并可以将该目标页面返回至相应的客户端,并在客户端上对该目标页面上的网络资源进行加载。在该实施例中,提出了一种前端资源自适应加载方法,其核心在于能够根据页面访问请求中所包含的标识信息自动判断客户端是否具备访问CDN资源的权限,并据此返回合适的页面版本,从而在无需人工介入的情况下,实现资源的高效、智能加载。上述方法在公有云和专有云环境下均能保持良好的适应性和性能,从而实现了提高网络资源的加载效率的技术效果,解决了网络资源的加载效率低的技术问题。
[0300] 本领域普通技术人员可以理解,图15所示的结构仅为示意,计算机终端A也可以是智能手机(如Android手机、iOS手机等)、平板电脑、掌上电脑以及移动互联网设备(MobileInternet Devices,简称为MID)、PAD等终端设备。图15其并不对上述计算机终端A的结构造成限定。例如,计算机终端A还可包括比图15中所示更多或者更少的组件(如网络接口、显示装置等),或者具有与图15所示不同的配置。
[0301] 本领域普通技术人员可以理解上述实施例的各种方法中的全部或部分步骤是可以通过程序来指令终端设备相关的硬件来完成,该程序可以存储于一计算机可读存储介质中,存储介质可以包括:闪存盘、只读存储器(Read-OnlyMemory,简称为ROM)、随机存取器(Random Access Memory,简称为RAM)、磁盘或光盘等。
[0302] 本申请的实施例还提供了一种计算机可读存储介质。可选地,在本实施例中,上述计算机可读存储介质可以用于保存上述实施例一所提供的网络资源的加载方法所执行的程序代码。
[0303] 可选地,在本实施例中,上述计算机可读存储介质可以位于计算机网络中计算机终端群中的任意一个计算机终端中,或者位于移动终端群中的任意一个移动终端中。
[0304] 可选地,在本实施例中,计算机可读存储介质被设置为存储用于执行上述网页资源的加载方法中的步骤的程序代码。
[0305] 本申请的实施例可以提供一种电子设备,该电子设备可以包括存储器和处理器。
[0306] 图16是根据本申请实施例的一种网络资源的加载方法的电子设备的框图。电子设备旨在表示各种形式的数字计算机,诸如,膝上型计算机、台式计算机、工作台、个人数字助理、服务器、刀片式服务器、大型计算机、和其它适合的计算机。电子设备还可以表示各种形式的移动装置,诸如,个人数字处理、蜂窝电话、智能电话、可穿戴设备和其它类似的计算装置。本文所示的部件、它们的连接和关系、以及它们的功能仅仅作为示例,并且不意在限制本文中描述的和 / 或者要求的本申请的实现。
[0307] 如图16所示,设备1600包括计算单元1601,其可以根据存储在只读存储器(ROM)1602中的计算机程序或者从存储单元1608加载到随机访问存储器(RAM)1603中的计算机程序,来执行各种适当的动作和处理。在RAM1603中,还可存储设备1600操作所需的各种程序和数据。计算单元1601、ROM1602以及RAM1603通过总线1604彼此相连。输入 / 输出(I / O)接口1605也连接至总线1604。
[0308] 设备1600中的多个部件连接至I / O接口1605,包括:输入单元1606,例如键盘、鼠标等;输出单元1604,例如各种类型的显示器、扬声器等;存储单元1608,例如磁盘、光盘等;以及通信单元1609,例如网卡、调制解调器、无线通信收发机等。通信单元1609允许设备1600通过诸如因特网的计算机网络和 / 或各种电信网络与其它设备交换信息 / 数据。
[0309] 计算单元1601可以是各种具有处理和计算能力的通用和 / 或专用处理组件。计算单元1601的一些示例包括但不限于中央处理单元(CPU)、图形处理单元(GraphicsProcessing Unit,简称为GPU)、各种专用的人工智能(Artificial Intelligence,简称为AI)计算芯片、各种运行机器学习模型算法的计算单元、数字信号处理器(Digital SignalProcessor,简称为DSP)、以及任何适当的处理器、控制器、微控制器等。计算单元1601执行上文所描述的各个方法和处理,例如网络资源的加载方法。例如,在一些实施例中,网络资源的加载方法可被实现为计算机软件程序,其被有形地包含于机器可读介质,例如存储单元1608。在一些实施例中,计算机程序的部分或者全部可以经由ROM 1602和 / 或通信单元1609而被载入和 / 或安装到设备1600上。当计算机程序加载到RAM 1603并由计算单元1601执行时,可以执行上文描述的网络资源的加载方法的一个或多个步骤。备选地,在其它实施例中,计算单元1601可以通过其它任何适当的方式(例如,借助于固件)而被配置为执行网络资源的加载方法。
[0310] 本申请的实施例还提供了一种计算机程序产品。可选地,在本实施例中,上述计算机程序产品中可以包括计算机程序,计算机程序在被处理器执行时实现上述本申请实施例的网络资源的加载方法。
[0311] 根据本申请实施例,提供了一种网络资源的加载方法,需要说明的是,在附图的流程图示出的步骤可以在诸如一组计算机可执行指令的计算机系统中执行,并且,虽然在流程图中示出了逻辑顺序,但是在某些情况下,可以以不同于此处的顺序执行所示出或描述的步骤。
[0312] 本申请实施例所提供的方法实施例可以在移动终端、计算机终端或者类似的运算装置中执行。图17是根据本申请实施例的一种用于实现网络资源的加载方法的计算机终端(或移动设备)的硬件结构框图,如图17所示,计算机终端170(或移动设备)可以包括一个或多个(图中采用1702a、1702b,……,1702n来示出)处理器1702(处理器1702可以包括但不限于微处理器(MicroControllerUnit,简称为MCU)或可编程逻辑器件(Field ProgrammableGate Array,简称为FPGA)等的处理装置)、用于存储数据的存储器1704、以及用于通信功能的传输装置1706。除此以外,还可以包括:显示器、输入 / 输出接口(I / O接口)、通用串行总线(Universal Serial Bus,简称为USB)端口(可以作为BUS总线的端口中的一个端口被包括)、网络接口、电源和 / 或相机。本领域普通技术人员可以理解,图17所示的结构仅为示意,其并不对上述电子装置的结构造成限定。例如,计算机终端170还可包括比图17中所示更多或者更少的组件,或者具有与图17所示不同的配置。
[0313] 图17示出的硬件结构框图,不仅可以作为上述计算机终端170(或移动设备)的示例性框图,还可以作为上述服务器的示例性框图,一种可选实施例中,图17以框图示出了使用上述图17所示的计算机终端170(或移动设备)作为计算环境1701中计算节点的一种实施例。
[0314] 图18是根据本申请实施例的一种网络资源的加载方法的计算环境的结构框图,如图18所示,计算环境1801包括运行在分布式网络上的多个(图中采用1810-1,1810-2,…,来示出)计算节点(如服务器)。计算节点都包含本地处理和内存资源,终端用户1802可以在计算环境1801中远程运行应用程序或存储数据。应用程序可以作为计算环境1801中的多个服务1820-1,1820-2,1820-3和1820-4进行提供,分别代表服务"F”,"G”,"I”和"H”。
[0315] 终端用户1802可以通过客户端上的Web浏览器或其它软件应用程序提供和访问服务,在一些实施例中,可以将终端用户1802的供应和 / 或请求提供给入口网关1830。入口网关1830可以包括一个相应的代理来处理针对服务(计算环境1801中提供的一个或多个服务)的供应和 / 或请求。
[0316] 服务是根据计算环境1801支持的各种虚拟化技术来提供或部署的。在一些实施例中,可以根据基于虚拟机(VirtualMachine,简称为VM)的虚拟化、基于容器的虚拟化和 / 或类似的方式提供服务。基于虚拟机的虚拟化可以是通过初始化虚拟机来模拟真实的计算机,在不直接接触任何实际硬件资源的情况下执行程序和应用程序。在虚拟机虚拟化机器的同时,根据基于容器的虚拟化,可以启动容器来虚拟化整个操作系统,以便多个工作负载可以在单个操作系统实例上运行。
[0317] 在基于容器虚拟化的一个实施例中,服务的若干容器可以被组装成一个Pod(例如,Kubernetes Pod)。举例来说,如图18所示,服务1820-2可以配备一个或多个Pod1840-1,1840-2,…,1840-N(统称为Pod)。Pod可以包括代理1845和一个或多个容器1842-1,1842-2,…,1842-M(统称为容器)。Pod中一个或多个容器处理与服务的一个或多个相应功能相关的请求,代理1845通常控制与服务相关的网络功能,如路由、负载均衡等。其它服务也可以配备类似于Pod的Pod。
[0318] 在操作过程中,执行来自终端用户1802的用户请求可能需要调用计算环境1801中的一个或多个服务,执行一个服务的一个或多个功能可能需要调用另一个服务的一个或多个功能。如图18所示,服务"F”1820-1从入口网关1830接收终端用户1802的用户请求,服务"F”1820-1可以调用服务"G”120-2,服务"G”1820-2可以请求服务"I”1820-3执行一个或多个功能。
[0319] 上述的计算环境可以是云计算环境,资源的分配由云服务提供上管理,允许功能的开发无需分析实现、调整或扩展服务器。该计算环境允许开发人员在不构建或维护复杂基础设施的情况下执行响应事件的代码。服务可以被分割完成一组可以自动独立伸缩的功能,而不是扩展单个硬件设备来处理潜在的负载。
[0320] 本文中以上描述的系统和技术的各种实施方式可以在数字电子电路系统、集成电路系统、场可编程门阵列(FPGA)、专用集成电路(Application Specific Integrated,简称为ASIC)、专用标准产品(Application Specific Standard Parts,简称为ASSP)、芯片上系统的系统(System-on-a-Chip,简称为SOC)、复杂可编程逻辑设备(Complex ProgrammableLogic Device,简称为CPLD)、计算机硬件、固件、软件、和 / 或它们的组合中实现。上述各种实施方式可以包括:实施在一个或者多个计算机程序中,该一个或者多个计算机程序可在包括至少一个可编程处理器的可编程系统上执行和 / 或解释,该可编程处理器可以是专用或者通用可编程处理器,可以从存储系统、至少一个输入装置、和至少一个输出装置接收数据和指令,并且将数据和指令传输至该存储系统、该至少一个输入装置、和该至少一个输出装置。
[0321] 用于实施本申请的方法的程序代码可以采用一个或多个编程语言的任何组合来编写。上述程序代码可以提供给通用计算机、专用计算机或其它可编程数据处理装置的处理器或控制器,使得程序代码当由处理器或控制器执行时使流程图和 / 或框图中所规定的功能 / 操作被实施。程序代码可以完全在机器上执行、部分地在机器上执行,作为独立软件包部分地在机器上执行且部分地在远程机器上执行或完全在远程机器或服务器上执行。
[0322] 在本申请的上下文中,机器可读介质可以是有形的介质,其可以包含或存储以供指令执行系统、装置或设备使用或与指令执行系统、装置或设备结合地使用的程序。机器可读介质可以是机器可读信号介质或机器可读储存介质。机器可读介质可以包括但不限于电子的、磁性的、光学的、电磁的、红外的、或半导体系统、装置或设备,或者上述内容的任何合适组合。机器可读存储介质的更具体示例会包括基于一个或多个线的电气连接、便携式计算机盘、硬盘、随机存取存储器(RAM)、只读存储器(ROM)、可擦除可编程只读存储器(Erasable Programmable Read-Only Memory,简称为EPROM或快闪存储器)、光纤、便捷式紧凑盘只读存储器(Compact Disc Read-Only Memory,简称为CD-ROM)、光学储存设备、磁储存设备、或上述内容的任何合适组合。
[0323] 为了提供与用户的交互,可以在计算机上实施此处描述的系统和技术,该计算机具有:用于向用户显示信息的显示装置(例如,阴极射线管(Cathode Ray Tube,简称为CRT)或者液晶显示器(Liquid Crystal Display,简称为LCD)、监测器;以及键盘和指向装置(例如,鼠标或者路径球),用户可以通过该键盘和该指向装置来将输入提供给计算机。其它种类的装置还可以用于提供与用户的交互;例如,提供给用户的反馈可以是任何形式的传感反馈(例如,视觉反馈、听觉反馈、或者触觉反馈);并且可以用任何形式(包括声输入、语音输入或者、触觉输入)来接收来自用户的输入。
[0324] 可以将此处描述的系统和技术实施在包括后台部件的计算系统(例如,作为数据服务器)、或者包括中间件部件的计算系统(例如,应用服务器)、或者包括前端部件的计算系统(例如,具有图形用户界面或者网络浏览器的用户计算机,用户可以通过该图形用户界面或者该网络浏览器来与此处描述的系统和技术的实施方式交互)、或者包括这种后台部件、中间件部件、或者前端部件的任何组合的计算系统中。可以通过任何形式或者介质的数字数据通信(例如,通信网络)来将系统的部件相互连接。通信网络的示例包括:局域网(Local Area Network,简称为LAN)、广域网(Wide Area Network,简称为WAN)和互联网。
[0325] 计算机系统可以包括客户端和服务器。客户端和服务器一般远离彼此并且通常通过通信网络进行交互。通过在相应的计算机上运行并且彼此具有客户端-服务器关系的计算机程序来产生客户端和服务器的关系。服务器可以是云服务器,也可以为分布式系统的服务器,或者是结合了区块链的服务器。
[0326] 需要说明的是,上述本申请实施例序号仅仅为了描述,不代表实施例的优劣。
[0327] 在本申请的上述实施例中,对各个实施例的描述都各有侧重,某个实施例中没有详述的部分,可以参见其它实施例的相关描述。
[0328] 在本申请所提供的几个实施例中,应该理解到,所揭露的技术内容,可通过其它的方式实现。其中,以上所描述的装置实施例仅仅是示意性的,例如单元的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式,例如多个单元或组件可以结合或者可以集成到另一个系统,或一些特征可以忽略,或不执行。另一点,所显示或讨论的相互之间的耦合或直接耦合或通信连接可以是通过一些接口,单元或模块的间接耦合或通信连接,可以是电性或其它的形式。
[0329] 作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是或者也可以不是物理单元,即可以位于一个地方,或者也可以分布到多个网络单元上。可以根据实际的需要选择其中的部分或者全部单元来实现本实施例方案的目的。
[0330] 另外,在本申请各个实施例中的各功能单元可以集成在一个处理单元中,也可以是各个单元单独物理存在,也可以两个或两个以上单元集成在一个单元中。上述集成的单元既可以采用硬件的形式实现,也可以采用软件功能单元的形式实现。
[0331] 集成的单元如果以软件功能单元的形式实现并作为独立的产品销售或使用时,可以存储在一个计算机可读取存储介质中。基于这样的理解,本申请的技术方案本质上或者说对现有技术做出贡献的部分或者该技术方案的全部或部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质中,包括若干指令用以使得一台计算机设备(可为个人计算机、服务器或者网络设备等)执行本申请各个实施例方法的全部或部分步骤。而前述的存储介质包括:U盘、只读存储器、随机存取存储器、移动硬盘、磁碟或者光盘等各种可以存储程序代码的介质。
[0332] 以上仅是本申请的优选实施方式,应当指出,对于本技术领域的普通技术人员来说,在不脱离本申请原理的前提下,还可以做出若干改进和润饰,上述改进和润饰也应视为本申请的保护范围。< / script>
Claims
1. A method for loading network resources, characterized in that: Applicable to servers, including: Obtaining a page access request from a client, wherein the page access request is used to request an access page from the server; In response to the page access request, identifying identification information from the page access request, wherein the identification information is used to indicate the client's authority to access the content distribution network; Determine at least one target page that matches the identification information, and a network resource that matches the identification information, wherein the page type of the target page corresponds to the authority corresponding to the identification information, the source of the network resource corresponds to the authority corresponding to the identification information, the page type includes a first type page and a second type page, the first type page is a page that uses the network resource of the content distribution network, and the second type page is a page that uses the network resource of the current site corresponding to the content distribution network; The target page is returned to the client, and the network resource is loaded into the target page.
2. The method according to claim 1, characterized in that: Determining at least one target page matching the identification information and a network resource matching the identification information includes: In response to the identification information indicating that the client is allowed to access the content distribution network, determining at least one first type page matching the content distribution network and the network resource from the content distribution network; In response to the identification information indicating that the client is prohibited from accessing the content distribution network, at least one second type page matching the local site and the network resources from the local site are determined, wherein the network resources are allowed to be cached by the local site on the content distribution network.
3. The method according to claim 2, characterized in that Returning the target page to the client and loading the network resource into the target page includes: When the identification information indicates that the client is allowed to access the content distribution network, returning the first type of page to the client; When the first type page is running on the client, the network resource from the content distribution network is loaded into the first type page.
4. The method according to claim 2, characterized in that: Returning the target page to the client and loading the network resource into the target page includes: When the identification information indicates that the client is prohibited from accessing the content distribution network, returning the second type of page to the client; When the second type page is running on the client, the network resource from the local website is loaded into the second type page.
5. The method according to claim 1, characterized in that In response to the page access request, identifying identification information from the page access request includes: In response to the page access request, obtaining a data file from the page access request, wherein the data file is stored by the client; The identification information is identified from the data file.
6. The method according to claim 5, characterized in that Obtaining a data file from the page access request, including: The interceptor is called to obtain the data file from the page access request.
7. The method according to claim 6, characterized in that Identifying the identification information from the data file includes: Using the interceptor, identifying the domain name of the content distribution network from the data file; The interceptor is used to obtain the identification information associated with the domain name, wherein the identification information is used to indicate the authority of the client to access the domain name of the content distribution network.
8. The method according to any one of claims 1 to 7, characterized in that The method further comprises: In response to a failure to identify the identification information from the page access request, at least one first type of page matching the content distribution network and the network resource from the content distribution network are determined.
9. A method for loading network resources, characterized in that: Applied to the client, including: Sending a page access request to a server, wherein the page access request is used to request the server to access a page; Load at least one target page returned by the server in response to the page access request, and load corresponding network resources on the target page, wherein the identification information is used to indicate the client's authority to access the content distribution network, the page type of the target page corresponds to the authority corresponding to the identification information, the source of the network resource corresponds to the authority corresponding to the identification information, the page type includes a first type page and a second type page, the first type page is a page that uses the network resources of the content distribution network, and the second type page is a page that uses the network resources of the site corresponding to the content distribution network.
10. The method according to claim 9, characterized in that The client stores a data file, the data file includes the identification information, and sends a page access request to the server, including: The page access request carrying the data file is sent to the server.
11. The method according to claim 10, characterized in that The method further comprises: In response to a failure in requesting the content distribution network to load the network resource on a first type of page, a request is made to a local site corresponding to the content distribution network to load the network resource on the first type of page, and the identification information is added to the data file, wherein the network resource is allowed to be cached by the local site on the content distribution network, and the identification information is used to indicate that the client is prohibited from accessing the content distribution network.
12. The method according to claim 11, characterized in that In response to a failure in requesting the content distribution network to load the network resource on a first type page, requesting the local station corresponding to the content distribution network to load the network resource on the first type page, and adding the identification information to the data file, comprising: In response to a failure in requesting the content distribution network to load the network resource on the first type page, triggering an abnormal event of a resource tag in the first type page; In response to the abnormal event, a request is made to the local site to load the network resource on the first type page, and the identification information is added to the data file.
13. The method according to claim 11, characterized in that The method further comprises: The first type of page generated by the plug-in or script is obtained.
14. The method according to claim 10, characterized in that The method further comprises: In response to completing loading the network resource of the local site corresponding to the content distribution network on the second type page, and detecting that the client is allowed to access the content distribution network, adding the identification information to the data file, wherein the network resource is allowed to be cached by the local site on the content distribution network, and the identification information is used to indicate that the client is allowed to access the content distribution network.
15. The method according to claim 14, characterized in that In response to completing loading of the network resource of the site corresponding to the content distribution network on the second type page and detecting that the client is allowed to access the content distribution network, adding the identification information to the data file comprises: Identifying a resource tag from the second type of page, wherein the resource tag includes the local address of the local website; In response to completing the loading of the network resource at the local site address in the resource tag on the second type page and detecting that the client is allowed to access the content distribution network, the second type page is used to trigger adding the identification information to the data file.
16. The method according to claim 14, characterized in that The method further comprises: The second type page generated by the plug-in or script is obtained.
17. A method for loading network resources, characterized in that: Applied to a server, a plug-in is installed on the server, and the server is used to call the plug-in to execute the following method: Obtaining a page access request from a client, wherein the page access request is used to request an access page from the server; In response to the page access request, identifying identification information from the page access request, wherein the identification information is used to indicate the client's authority to access the content distribution network; Determine at least one target page that matches the identification information, and a network resource that matches the identification information, wherein the page type of the target page corresponds to the authority corresponding to the identification information, the source of the network resource corresponds to the authority corresponding to the identification information, the page type includes a first type page and a second type page, the first type page is a page that uses the network resource of the content distribution network, and the second type page is a page that uses the network resource of the current site corresponding to the content distribution network; The target page is returned to the client, and the network resource is loaded into the target page.
18. A network resource loading system, characterized in that: The system is deployed in a public network or a private network, and the system includes: a client and a server, wherein: The client is used to send a page access request to the server, wherein the page access request is used to request the server to access a page; The server is used to identify identification information from the page access request in response to the page access request, wherein the identification information is used to indicate the client's authority to access the content distribution network; determine at least one target page matching the identification information, and a network resource matching the identification information, wherein a page type of the target page corresponds to the authority corresponding to the identification information, a source of the network resource corresponds to the authority corresponding to the identification information, the page type includes a first type page and a second type page, the first type page is a page that uses the network resource of the content distribution network, and the second type page is a page that uses the network resource of the site corresponding to the content distribution network; The client is used to load the target page returned by the server and load network resources on the target page.
19. An electronic device, characterized in that: include: A memory storing an executable program; A processor, configured to run the program, wherein the program executes the method according to any one of claims 1 to 17 when running.
20. A computer-readable storage medium, characterized in that: The computer-readable storage medium includes a stored executable program, wherein when the executable program is run, the device where the storage medium is located is controlled to execute the method according to any one of claims 1 to 17.
21. A computer program product, characterized in that It comprises a computer program which, when executed by a processor, implements the method according to any one of claims 1 to 17.
Citation Information
Patent Citations
Network resource access method, computer equipment and storage medium
CN110392022A