A method, device and computer program product for dynamically replacing static resource URL
By building Proxy proxy objects in front-end development projects and using get traps to determine the optimal CDN resource domain name, the problem of low CDN node selection efficiency in the existing technology is solved, and the resource loading speed and configuration efficiency are improved.
Patent Information
- Application Number
- CN202411832702.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-13
- Publication Date
- 2025-04-18
- Estimated Expiration
- 2044-12-13
AI Technical Summary
The prior art is difficult to dynamically select the optimal CDN node in front-end development projects, resulting in slow resource loading speed, high manual configuration cost and low efficiency.
By building a Proxy proxy object, using the get trap in the Proxy proxy object to intercept CDN resource access requests, combining the alternative static resource library to determine the optimal CDN resource domain name, and generate the optimal static resource URL, dynamically replace the specified static resource URL.
It realizes dynamic selection of the optimal CDN node without manual intervention, which improves resource loading speed and operating performance, while reducing costs and configuration efficiency.
Smart Images

Figure CN119293356B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of data processing, and in particular relates to a method, a device and a computer program product for dynamically replacing a static resource URL. Background Art
[0002] In front-end development projects, developers will generate or use different domain names according to different environments or configurations to obtain static resource URLs (uniform resource locators). During development, developers will first develop the project locally, then use the build tool to package the front-end source code to generate code, and finally deploy the front-end static resource files corresponding to the code to the server for loading and access.
[0003] At present, in front-end development projects, static resource URLs are usually configured to use different domain names in different environments or to be deployed on different servers. Among them, the traditional static resource URL configuration method is usually fixed, that is, the developer manually configures the static resource URL, that is, configures the domain name in the static resource URL. This has the following shortcomings: (1) It is difficult to dynamically select the optimal CDN node (that is, select the optimal domain name) at runtime, which will result in slower resource loading speed and thus reduce operating performance; (2) Manual configuration is not only costly, but also reduces configuration efficiency. Therefore, based on the above shortcomings, how to provide a dynamic replacement method for static resource URLs that can select the optimal CDN node during configuration and has low cost and high efficiency has become a problem to be solved urgently. Summary of the invention
[0004] The purpose of the present invention is to provide a method, device and computer program product for dynamically replacing a static resource URL, so as to solve the problems that the prior art uses developers to manually configure the static resource URL, such as being unable to dynamically select the optimal domain name, high cost and low efficiency.
[0005] In order to achieve the above object, the present invention adopts the following technical solutions:
[0006] In a first aspect, a method for dynamically replacing a static resource URL is provided, comprising:
[0007] Get the specified static resource URL and construct a Proxy object for the specified static resource URL;
[0008] Access the Proxy object to obtain the get trap of the Proxy object;
[0009] Executing the get trap to intercept the CDN resource access request based on the get trap, and after intercepting the CDN resource access request, using the alternative static resource library to determine the optimal CDN resource domain name;
[0010] Generate an optimal static resource URL based on the Proxy object and the optimal CDN resource domain name;
[0011] The optimal static resource URL is used to perform a replacement process on the designated static resource URL, so as to complete the dynamic replacement of the designated static resource URL after the replacement process.
[0012] Based on the above disclosed content, the present invention constructs a Proxy proxy object for the specified static resource URL when configuring the static resource URL, and uses the Proxy proxy object to configure the URL, wherein the specific configuration process of the URL is: first, by accessing the Proxy proxy object, to obtain the get trap in the Proxy proxy object (which is used to intercept access requests to the object), then, execute the get trap to intercept the CDN resource access request, and after intercepting the CDN resource access request, determine the optimal CDN resource domain name from the alternative static resource library; then, the Proxy proxy object and the optimal CDN resource domain name can be used to generate the optimal static resource URL; finally, the optimal static resource URL is used to replace the aforementioned specified static resource URL, and the dynamic configuration of the specified static resource URL can be completed.
[0013] Through the above design, the present invention uses the Proxy object to realize the dynamic replacement of static resource URLs without manual intervention, which not only reduces the cost but also improves the configuration efficiency; at the same time, the present invention also uses the get trap in the Proxy object to determine the optimal CDN resource domain name from the candidate static resource library after receiving the CDN resource access request, and finally, based on the optimal CDN resource domain name, the optimal static resource URL can be generated; based on this, compared with the traditional technology, the present invention realizes the dynamic selection of the optimal CDN node, which can ensure the loading speed of resources and thus improve the operation performance; therefore, the present invention can realize the dynamic configuration of CDN resource access URL on the basis of ensuring access performance, so it is very suitable for large-scale application and promotion.
[0014] In a possible design, the Proxy object includes a first proxy object and a second proxy object, wherein the attribute value of the first proxy object is used to return the second proxy object in the Proxy object;
[0015] Access the Proxy object and obtain the get trap of the Proxy object, including:
[0016] Accessing the properties of the first proxy object to obtain the property value of the first proxy object;
[0017] Accessing the Proxy object according to the attribute value to return a second proxy object from the Proxy object;
[0018] Accessing properties of the second proxy object to determine proxy parameters from the properties of the second proxy object;
[0019] Based on the proxy parameters, a get trap of the Proxy proxy object is obtained.
[0020] In a possible design, the candidate static resource library stores several candidate static resource URLs, wherein the optimal CDN resource domain name is determined by using the candidate static resource library, including:
[0021] Get the specified running resources;
[0022] Using each candidate static resource URL, loading the specified running resource to obtain a loading response time of each candidate static resource URL;
[0023] Filter out the shortest loading response time from various loading response times;
[0024] The candidate static resource URL corresponding to the shortest loading response time is used as the optimal candidate static resource URL;
[0025] The optimal CDN resource domain name is obtained according to the optimal candidate static resource URL.
[0026] In a possible design, generating an optimal static resource URL based on the Proxy object and the optimal CDN resource domain name includes:
[0027] Get the resource access path;
[0028] The optimal static resource URL is generated by utilizing the Proxy object and based on the resource access path and the optimal CDN resource domain name.
[0029] In a possible design, the resource access path is string data;
[0030] Wherein, using the Proxy object and based on the resource access path and the optimal CDN resource domain name, generating the optimal static resource URL includes:
[0031] Using the Proxy object, convert the optimal CDN resource domain name into a string to obtain the optimal resource domain name string;
[0032] The optimal resource domain name character string and the resource access path are concatenated to obtain the optimal static resource URL after the concatenation.
[0033] In a possible design, the Proxy object includes a first proxy object and a second proxy object, wherein the property value of the first proxy object is used to return the second proxy object in the Proxy object, and the second proxy object is used to call an implicit conversion function;
[0034] The Proxy object is used to convert the optimal CDN resource domain name into a string to obtain the optimal resource domain name string, including:
[0035] Using the second proxy object in the Proxy proxy object, calling an implicit conversion function;
[0036] Based on the implicit conversion function, the optimal CDN resource domain name is subjected to a character string conversion process, so as to obtain the optimal resource domain name character string after the character string conversion process.
[0037] In one possible design, the determined optimal CDN resource domain name is a temporary Proxy object, wherein the implicit conversion function is used to convert the data type of the temporary Proxy object to obtain an optimal resource domain name string of the same data type as the resource access path.
[0038] In a second aspect, a device for dynamically replacing a static resource URL is provided, comprising:
[0039] A proxy object construction unit, used to obtain a specified static resource URL and construct a Proxy object of the specified static resource URL;
[0040] An object access unit, used to access the Proxy proxy object to obtain a get trap of the Proxy proxy object;
[0041] A URL processing unit, configured to execute the get trap, intercept the CDN resource access request based on the get trap, and determine the optimal CDN resource domain name by using the alternative static resource library after intercepting the CDN resource access request;
[0042] The URL processing unit is further used to generate an optimal static resource URL based on the Proxy object and the optimal CDN resource domain name;
[0043] The replacement unit is used to use the optimal static resource URL to perform replacement processing on the specified static resource URL, so as to complete the dynamic replacement of the specified static resource URL after the replacement processing.
[0044] In the third aspect, another device for dynamically replacing a static resource URL is provided. Taking the device as an electronic device as an example, the device includes a memory, a processor and a transceiver which are communicatively connected in sequence, wherein the memory is used to store a computer program, the transceiver is used to send and receive messages, and the processor is used to read the computer program to execute the method for dynamically replacing the static resource URL as in the first aspect or any one of the possible designs in the first aspect.
[0045] In a fourth aspect, a storage medium is provided, on which instructions are stored. When the instructions are executed on a computer, the method for dynamically replacing the static resource URL as in the first aspect or any possible design in the first aspect is executed.
[0046] In a fifth aspect, a computer program product comprising instructions is provided, which, when executed on a computer, causes the computer to execute the method for dynamically replacing the static resource URL as described in the first aspect or any possible design of the first aspect.
[0047] Beneficial effects:
[0048] (1) The present invention utilizes the Proxy object to realize the dynamic replacement of static resource URLs without manual intervention, thus not only reducing costs but also improving configuration efficiency. At the same time, the present invention also uses the get trap in the Proxy object to determine the optimal CDN resource domain name from the candidate static resource library after receiving a CDN resource access request. Finally, based on the optimal CDN resource domain name, the optimal static resource URL can be generated. Based on this, compared with the traditional technology, the present invention realizes the dynamic selection of the optimal CDN node, which can ensure the loading speed of resources and thus improve the operating performance. Therefore, the present invention can realize the dynamic configuration of the CDN resource access URL on the basis of ensuring the access performance, so that it is very suitable for large-scale application and promotion.
[0049] (2) The method provided by the present invention can be easily integrated into existing Web development projects and can be implemented with only a few lines of code without the need for complex configuration or additional server-side logic. Therefore, the operation is simple and easy to use and implement. BRIEF DESCRIPTION OF THE DRAWINGS
[0050] Figure 1 A schematic diagram of the steps of a method for dynamically replacing a static resource URL provided by an embodiment of the present invention;
[0051] Figure 2A schematic diagram of the structure of a device for dynamically replacing a static resource URL provided by an embodiment of the present invention;
[0052] Figure 3 A schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0053] In order to more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the present invention will be briefly introduced below in combination with the drawings and the description of the embodiments or the prior art. Obviously, the following description of the structure of the drawings is only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work. It should be noted that the description of these embodiments is used to help understand the present invention, but does not constitute a limitation of the present invention.
[0054] It should be understood that although the terms first, second, etc. may be used herein to describe various units, these units should not be limited by these terms. These terms are only used to distinguish one unit from another unit. For example, a first unit can be referred to as a second unit, and similarly, a second unit can be referred to as a first unit without departing from the scope of the exemplary embodiments of the present invention.
[0055] It should be understood that the term "and / or" that may appear in this article is merely a description of the association relationship between associated objects, indicating that three relationships may exist. For example, A and / or B can represent three situations: A exists alone, B exists alone, and A and B exist at the same time. The term " / and" that may appear in this article describes another type of association object relationship, indicating that two relationships may exist. For example, A / and B can represent two situations: A exists alone, and A and B exist alone. In addition, the character " / " that may appear in this article generally indicates that the previous and next associated objects are in an "or" relationship.
[0056] Example:
[0057] See also Figure 1As shown, the method for dynamically replacing the static resource URL provided in this embodiment creates a Proxy object for the static resource URL through an innovative JavaScript proxy mechanism, and then uses the get trap in the Proxy object to determine the optimal CDN resource domain name from the candidate static resource library after receiving the CDN resource access request, and then, based on the optimal CDN resource domain name, the optimal static resource URL can be generated; finally, the aforementioned optimal static resource URL is used to replace the original static resource URL, and the dynamic replacement of the original static resource URL can be completed; thus, through the above design, compared with the traditional technology, the method does not require manual intervention, which not only reduces the cost but also improves the configuration efficiency. At the same time, the present invention also realizes the dynamic selection of the optimal CDN node, which can ensure the loading speed of resources and thus improve the operation performance; therefore, the method is very suitable for large-scale application and promotion; wherein, for example, the method can be, but not limited to, run on the URL configuration end side, and optionally, the URL configuration end can be, but not limited to, a personal computer (PC). It can be understood that the aforementioned execution subject does not constitute a limitation on the embodiment of the present application, and accordingly, the operation steps of the method can be, but not limited to, as shown in the following steps S1 to S5.
[0058] S1. Obtain a specified static resource URL and construct a Proxy object of the specified static resource URL. In this embodiment, a proxy object library may be pre-set, in which Proxy objects corresponding to different static resource URLs are stored. Therefore, after obtaining the aforementioned specified static resource URL, the corresponding Proxy object may be obtained by matching it in the proxy object library. The Proxy object is created by using Proxy (a built-in object in JavaScript that allows interception and customization of operations on an object), and then some behaviors of the specified object may be customized by operating the proxy object. Therefore, in this embodiment, the Proxy object is used to dynamically replace the static resource URL, and in the replacement process, the Proxy object is used to select the optimal CDN node, that is, the optimal CDN domain name (which refers to the domain name of the acceleration service of the Content Delivery Network (CDN)) to ensure that the replaced URL can achieve the optimal loading speed.
[0059] Optionally, the Proxy object is taken as a two-layer object, that is, it includes a first proxy object and a second proxy object, wherein the attribute value of the first proxy object is used to return the second proxy object in the Proxy proxy object, and the second proxy object is used to call an implicit conversion function; based on this, the first proxy object is a value object, which is used to deconstruct the entire Proxy proxy object, and its attribute value represents a Proxy object (i.e., the second proxy object) that can be calculated using privacy transformation. Therefore, using this attribute value, the aforementioned second proxy object can be returned; finally, the second proxy object can be used to select the optimal CDN node and generate a complete optimal static resource URL for replacing the aforementioned specified static resource URL.
[0060] The dynamic selection process of the optimal CDN node (ie, the optimal CDN resource domain name described below) may be, but is not limited to, as shown in the following steps S2 and S3.
[0061] S2. Access the Proxy object to obtain a get trap of the Proxy object. In a specific implementation, the get trap is an attribute of the Proxy object, which is a function used to intercept access requests to the attributes of the proxy object. Therefore, this implementation responds to the dynamic selection operation of the optimal CDN resource domain name based on the get trap (the selection process is described below). At the same time, it has been explained above that the Proxy object is a two-layer object. Therefore, it is necessary to access two layers of objects to obtain the get trap. The process can be but is not limited to the following steps S21 to S24.
[0062] S21. Access the properties of the first proxy object to obtain the property values of the first proxy object; in this embodiment, the first proxy object is actually also a Proxy object, which is provided with multiple properties (such as name, etc.), and each property corresponds to an attribute value; therefore, this embodiment returns the second-layer proxy object by accessing the attribute values in the constructed Proxy object, so that the returned second-layer proxy object (i.e., the second proxy object) can be used to obtain the get trap later; of course, in this embodiment, the properties of the aforementioned first proxy object are set to an object return string, and its attribute value is used to return the second proxy object.
[0063] In this way, after obtaining the attribute value of the first proxy object, the second proxy object can be returned from the Proxy object based on the attribute value, and the process can be but not limited to the following step S22.
[0064] S22. According to the attribute value, access the Proxy object to return the second proxy object from the Proxy object; in this embodiment, after obtaining the second proxy object, the attributes of the second proxy object can be obtained so as to obtain the aforementioned get trap from the attributes of the second proxy object; wherein, the specific acquisition process of the get trap can be but is not limited to as shown in the following steps S23 and S24.
[0065] S23. Access the properties of the second proxy object to determine the proxy parameters from the properties of the second proxy object; in this embodiment, the second proxy object can be regarded as the proxied object, and its properties are configured as multiple proxy parameters, including Handler parameters and Target parameters, etc., wherein the Target parameter represents the object to be intercepted, and the handler parameter is also an object used to customize the interception behavior; therefore, the aforementioned proxy parameter corresponds to a get method, and the get method is used to intercept access requests to the object properties; in this way, the aforementioned get trap can be determined based on the aforementioned proxy parameters, and the process is shown in the following step S24.
[0066] S24. Based on the proxy parameters, obtain a get trap of the Proxy proxy object.
[0067] In this way, through the aforementioned steps S21 to S24, the get trap of the Proxy proxy object can be obtained, and then, access interception can be performed based on the get trap. That is, in this embodiment, it is equivalent to using the get method of the Proxy proxy object to intercept the access request, and use this as a trigger condition for the dynamic selection of the optimal CDN resource domain name, and then after intercepting the access request, enter the dynamic selection process of the optimal CDN resource domain name.
[0068] The dynamic selection process of the optimal CDN resource domain name may be, but is not limited to, as shown in the following step S3.
[0069] S3. Execute the get trap to intercept CDN resource access requests based on the get trap, and after intercepting the CDN resource access requests, use the alternative static resource library to determine the optimal CDN resource domain name; in the specific implementation, the alternative static resource library stores a number of alternative static resource URLs, and this embodiment uses a small fragment network request method to determine the optimal CDN resource domain name from a number of alternative static resource URLs, and the process can be but is not limited to the following steps S31 to S35.
[0070] S31. Obtain designated running resources; in specific applications, for example, the designated running resources may be, but are not limited to, images or applets, that is, use the URLs of the alternative static resources in the alternative static resource library to load the aforementioned images or applets; then, determine the optimal CDN resource domain name based on the loading response time; optionally, the aforementioned process of determining the optimal CDN resource domain name based on the loading response time may be, but is not limited to, as shown in the following steps S32 to S35.
[0071] S32. Utilize each candidate static resource URL to load the specified running resource to obtain the loading response time of each candidate static resource URL; in this embodiment, after obtaining the loading response time of each candidate static resource URL to load the aforementioned specified running resource, the optimal CDN resource domain name can be determined based on the shortest loading response time, and the process can be but not limited to as shown in the following steps S33 and S34.
[0072] S33. Filter out the shortest loading response time from each loading response time; in specific implementation, the shorter the loading response time, the faster the loading speed of the specified running resource is, and the higher its running performance is; therefore, this embodiment filters out the shortest loading response time, and determines the optimal CDN resource domain name based on its corresponding alternative static resource URL, and the process is shown in the following steps S34 and S35.
[0073] S34. The alternative static resource URL corresponding to the shortest loading response time is used as the optimal alternative static resource URL.
[0074] S35. According to the optimal candidate static resource URL, the optimal CDN resource domain name is obtained; in this embodiment, the domain name of the optimal candidate static resource URL can be used as the optimal CDN resource domain name by way of example but is not limited thereto.
[0075] In this way, through the aforementioned steps S31 to S35, the optimal CDN resource domain name can be determined from the alternative static resource library; then, based on the optimal CDN resource domain name and using the Proxy proxy object, the optimal static resource URL can be generated; wherein, the generation process of the optimal static resource URL can be but is not limited to as shown in the following step S4.
[0076] S4. Generate an optimal static resource URL based on the Proxy object and the optimal CDN resource domain name. In this embodiment, for example, but not limited to, first obtain the resource access path; then, use the Proxy object and generate the optimal static resource URL based on the resource access path and the optimal CDN resource domain name; wherein, the resource access path is a string data, which can be pre-set in the URL configuration terminal and can be read when used.
[0077] At the same time, since the optimal CDN resource domain name is obtained by using the get method (i.e., get trap) in the attributes of the second proxy object, the determined optimal CDN resource domain name is actually a temporary Proxy object, and its data type is different from the data type of the resource access path; at the same time, when constructing the Proxy proxy object, this embodiment constructs a second proxy object for calling the implicit conversion function (the implicit conversion function is used to convert the data type of the aforementioned temporary Proxy object to obtain an optimal resource domain name string of the same data type as the resource access path). In this way, it is necessary to use the second proxy object to perform data type conversion of the optimal CDN resource domain name, and then, combined with the aforementioned pre-set resource access path, the optimal static resource URL can be generated.
[0078] Optionally, the aforementioned data type conversion process is: using the Proxy proxy object to convert the optimal CDN resource domain name into a string to obtain the optimal resource domain name string; specifically, using the second proxy object in the Proxy proxy object to call the implicit conversion function; then, based on the implicit conversion function, the optimal CDN resource domain name is subjected to string conversion processing to obtain the optimal resource domain name string after the string conversion processing; in this embodiment, the implicit conversion function is a commonly used function for data type conversion, and its principle will not be repeated.
[0079] In this way, after obtaining the optimal resource domain name string, the optimal resource domain name string and the resource access path are concatenated to obtain the optimal static resource URL.
[0080] Based on the aforementioned step S4, an optimal static resource URL can be generated, and then, the optimal static resource URL can be used to replace the aforementioned specified static resource URL. The process can be but is not limited to as shown in the following step S5.
[0081] S5. Use the optimal static resource URL to replace the specified static resource URL, so as to complete the dynamic replacement of the specified static resource URL after the replacement process; in this embodiment, it is equivalent to replacing the specified static resource URL with the aforementioned optimal static resource URL, thereby performing resource loading based on the optimal static resource URL.
[0082] Therefore, through the dynamic replacement method of static resource URL described in detail in the aforementioned steps S1 to S5, the present invention creates a Proxy object for the static resource URL through an innovative JavaScript proxy mechanism, and then uses the get trap in the Proxy object to determine the optimal CDN resource domain name from the alternative static resource library after receiving the CDN resource access request, and then, based on the optimal CDN resource domain name, the optimal static resource URL can be generated; finally, the aforementioned optimal static resource URL is used to replace the original static resource URL, and the dynamic replacement of the original static resource URL can be completed; thus, through the above design, compared with the traditional technology, the present method does not require manual intervention, which not only reduces the cost but also improves the configuration efficiency. At the same time, the present invention also realizes the dynamic selection of the optimal CDN node, which can ensure the loading speed of resources and thus improve the operation performance; therefore, the present method is very suitable for large-scale application and promotion.
[0083] like Figure 2 As shown, the second aspect of this embodiment provides a hardware device for implementing the method for dynamically replacing the static resource URL described in the first aspect of the embodiment, including:
[0084] The proxy object construction unit is used to obtain a specified static resource URL and construct a Proxy proxy object of the specified static resource URL.
[0085] The object access unit is used to access the Proxy proxy object to obtain the get trap of the Proxy proxy object.
[0086] The URL processing unit is used to execute the get trap to intercept the CDN resource access request based on the get trap, and after intercepting the CDN resource access request, use the alternative static resource library to determine the optimal CDN resource domain name.
[0087] The URL processing unit is also used to generate an optimal static resource URL based on the Proxy object and the optimal CDN resource domain name.
[0088] The replacement unit is used to use the optimal static resource URL to perform replacement processing on the specified static resource URL, so as to complete the dynamic replacement of the specified static resource URL after the replacement processing.
[0089] The working process, working details and technical effects of the device provided in this embodiment can be found in the first aspect of the embodiment and will not be described in detail here.
[0090] like Figure 3As shown, the third aspect of this embodiment provides another device for dynamically replacing a static resource URL. Taking the device as an electronic device as an example, the device includes: a memory, a processor and a transceiver that are communicatively connected in sequence, wherein the memory is used to store computer programs, the transceiver is used to send and receive messages, and the processor is used to read the computer program to execute the method for dynamically replacing a static resource URL as described in the first aspect of the embodiment.
[0091] For example, the memory may include, but is not limited to, random access memory (RAM), read only memory (ROM), flash memory, first input first output (FIFO) and / or first in last out (FILO), etc. Specifically, the processor may include one or more processing cores, such as a 4-core processor, an 8-core processor, etc. The processor may be implemented in at least one hardware form of DSP (Digital Signal Processing), FPGA (Field-Programmable Gate Array), and PLA (Programmable Logic Array). At the same time, the processor may also include a main processor and a coprocessor. The main processor is a processor for processing data in the awake state, also known as a CPU (Central Processing Unit); the coprocessor is a low-power processor for processing data in the standby state.
[0092] In some embodiments, the processor may be integrated with a GPU (Graphics Processing Unit), which is responsible for rendering and drawing the content to be displayed on the display screen. For example, the processor may not be limited to a microprocessor of the STM32F105 series, a reduced instruction set computer (RISC) microprocessor, an X86 architecture processor, or a processor with an integrated embedded neural network processing unit (NPU); the transceiver may be, but is not limited to, a wireless fidelity (WIFI) wireless transceiver, a Bluetooth wireless transceiver, a General Packet Radio Service (GPRS) wireless transceiver, a ZigBee protocol (a low-power LAN protocol based on the IEEE802.15.4 standard, ZigBee) wireless transceiver, a 3G transceiver, a 4G transceiver, and / or a 5G transceiver. In addition, the device may also include, but is not limited to, a power module, a display screen, and other necessary components.
[0093] The working process, working details and technical effects of the electronic device provided in this embodiment can be found in the first aspect of the embodiment and will not be described in detail here.
[0094] The fourth aspect of this embodiment provides a storage medium that stores instructions for the method for dynamically replacing the static resource URL described in the first aspect of the embodiment, that is, the storage medium stores instructions, and when the instructions are run on a computer, the method for dynamically replacing the static resource URL described in the first aspect of the embodiment is executed.
[0095] The storage medium refers to a carrier for storing data, which may include but is not limited to a floppy disk, a CD, a hard disk, a flash memory, a USB flash drive and / or a memory stick, and the computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices.
[0096] The working process, working details and technical effects of the storage medium provided in this embodiment can be found in the first aspect of the embodiment and will not be described in detail here.
[0097] The fifth aspect of this embodiment provides a computer program product comprising instructions, which, when executed on a computer, causes the computer to execute the method for dynamically replacing the static resource URL as described in the first aspect of the embodiment, wherein the computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device.
[0098] Finally, it should be noted that the above description is only a preferred embodiment of the present invention and is not intended to limit the protection scope of the present invention. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A method for dynamically replacing a static resource URL, characterized in that: include: Get the specified static resource URL and construct a Proxy object for the specified static resource URL; Access the Proxy object to obtain the get trap of the Proxy object; Executing the get trap to intercept the CDN resource access request based on the get trap, and after intercepting the CDN resource access request, using the alternative static resource library to determine the optimal CDN resource domain name; Generate an optimal static resource URL based on the Proxy object and the optimal CDN resource domain name; Using the optimal static resource URL, the designated static resource URL is replaced, so as to complete the dynamic replacement of the designated static resource URL after the replacement process; The Proxy object includes a first proxy object and a second proxy object, wherein the attribute value of the first proxy object is used to return the second proxy object in the Proxy object; Access the Proxy object and obtain the get trap of the Proxy object, including: Accessing the properties of the first proxy object to obtain the property value of the first proxy object; Accessing the Proxy object according to the attribute value to return a second proxy object from the Proxy object; Accessing properties of the second proxy object to determine proxy parameters from the properties of the second proxy object; Based on the proxy parameters, obtain the get trap of the Proxy proxy object; Based on the Proxy object and the optimal CDN resource domain name, an optimal static resource URL is generated, including: Get the resource access path; Using the Proxy object, and based on the resource access path and the optimal CDN resource domain name, generate the optimal static resource URL; The resource access path is string data; Wherein, using the Proxy object and based on the resource access path and the optimal CDN resource domain name, generating the optimal static resource URL includes: Using the Proxy object, convert the optimal CDN resource domain name into a string to obtain the optimal resource domain name string; Concatenate the optimal resource domain name character string and the resource access path to obtain the optimal static resource URL after the concatenation process; The Proxy object includes a first proxy object and a second proxy object, wherein the property value of the first proxy object is used to return the second proxy object in the Proxy object, and the second proxy object is used to call an implicit conversion function; The Proxy object is used to convert the optimal CDN resource domain name into a string to obtain the optimal resource domain name string, including: Using the second proxy object in the Proxy proxy object, calling an implicit conversion function; Based on the implicit conversion function, the optimal CDN resource domain name is subjected to a character string conversion process, so as to obtain the optimal resource domain name character string after the character string conversion process; The determined optimal CDN resource domain name is a temporary Proxy object, wherein the implicit conversion function is used to convert the data type of the temporary Proxy object to obtain an optimal resource domain name character string of the same data type as the resource access path.
2. The method according to claim 1, characterized in that: The candidate static resource library stores a number of candidate static resource URLs, wherein the optimal CDN resource domain name is determined by using the candidate static resource library, including: Get the specified running resources; Using each candidate static resource URL, loading the specified running resource to obtain a loading response time of each candidate static resource URL; Filter out the shortest loading response time from various loading response times; The candidate static resource URL corresponding to the shortest loading response time is used as the optimal candidate static resource URL; The optimal CDN resource domain name is obtained according to the optimal candidate static resource URL.
3. A device for dynamically replacing a static resource URL, characterized in that: include: A proxy object construction unit, used to obtain a specified static resource URL and construct a Proxy object of the specified static resource URL; An object access unit, used to access the Proxy proxy object to obtain a get trap of the Proxy proxy object; A URL processing unit, configured to execute the get trap, intercept the CDN resource access request based on the get trap, and determine the optimal CDN resource domain name by using the alternative static resource library after intercepting the CDN resource access request; The URL processing unit is further used to generate an optimal static resource URL based on the Proxy object and the optimal CDN resource domain name; A replacement unit, used to use the optimal static resource URL to perform a replacement process on the specified static resource URL, so as to complete the dynamic replacement of the specified static resource URL after the replacement process; The Proxy object includes a first proxy object and a second proxy object, wherein the attribute value of the first proxy object is used to return the second proxy object in the Proxy object; Access the Proxy object and obtain the get trap of the Proxy object, including: Accessing the properties of the first proxy object to obtain the property value of the first proxy object; Accessing the Proxy object according to the attribute value to return a second proxy object from the Proxy object; Accessing properties of the second proxy object to determine proxy parameters from the properties of the second proxy object; Based on the proxy parameters, obtain the get trap of the Proxy proxy object; Based on the Proxy object and the optimal CDN resource domain name, an optimal static resource URL is generated, including: Get the resource access path; Using the Proxy object, and based on the resource access path and the optimal CDN resource domain name, generate the optimal static resource URL; The resource access path is string data; Wherein, using the Proxy object and based on the resource access path and the optimal CDN resource domain name, generating the optimal static resource URL includes: Using the Proxy object, convert the optimal CDN resource domain name into a string to obtain the optimal resource domain name string; Concatenate the optimal resource domain name character string and the resource access path to obtain the optimal static resource URL after the concatenation process; The Proxy object includes a first proxy object and a second proxy object, wherein the property value of the first proxy object is used to return the second proxy object in the Proxy object, and the second proxy object is used to call an implicit conversion function; The Proxy object is used to convert the optimal CDN resource domain name into a string to obtain the optimal resource domain name string, including: Using the second proxy object in the Proxy proxy object, calling an implicit conversion function; Based on the implicit conversion function, the optimal CDN resource domain name is subjected to a character string conversion process, so as to obtain the optimal resource domain name character string after the character string conversion process; The determined optimal CDN resource domain name is a temporary Proxy object, wherein the implicit conversion function is used to convert the data type of the temporary Proxy object to obtain an optimal resource domain name character string of the same data type as the resource access path.
4. A device for dynamically replacing a static resource URL, characterized in that: include: A memory, a processor and a transceiver which are sequentially connected in communication, wherein the memory is used to store a computer program, the transceiver is used to send and receive messages, and the processor is used to read the computer program, and execute the method for dynamically replacing a static resource URL as described in any one of claims 1 to 2.
5. A computer program product comprising instructions, characterized in that When the instruction is executed on a computer, the computer is caused to execute the method for dynamically replacing a static resource URL as claimed in any one of claims 1 to 2.
Citation Information
Patent Citations
Online stream media playing method and stream media downloading and offline playing method
CN106657162A
System and method for updating application clients using plurality of content delivery networks
CN110383794A