A request sending method and apparatus, device, and storage medium
By downloading the polyfill code before the browser supports the fetch method and intercepting the request during the download process, the resource waste and request failure issues caused by compatibility issues are resolved, and efficient request sending is achieved.
Patent Information
- Application Number
- CN202310465131.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-04-26
- Publication Date
- 2025-11-07
- Estimated Expiration
- 2043-04-26
AI Technical Summary
In existing technologies, in order to be compatible with older browsers, all browsers download polyfills, which leads to a waste of resources, and requests are prone to failure during the polyfill download process.
The system uses a preset function to determine whether the browser supports the fetch method. If it does not, it triggers a polyfill to download the request. During the download process, it checks again whether the browser supports the fetch method. If not, it intercepts the request and stores it in a request array. Once the download is complete, it is converted into a fetch request and sent.
This effectively avoids all browsers downloading polyfills, prevents request failures during polyfill downloads, and improves resource utilization efficiency and request success rate.
Smart Images

Figure CN116599945B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of front-end, in particular to a request sending method and device, equipment and storage medium. BACKGROUND
[0002] In the prior art, for the scenario of initiating an HTTP (HyperText Transfer Protocol) request through a fetch method on a low-version browser, a babel (a JavaScript compiler that can convert new version JavaScript syntax code into backward compatible JavaScript syntax so that the converted code can run normally in an old version browser) is used to package a polyfill code file corresponding to the fetch method into a product to implement the compatibility of the fetch during application construction. However, this construction method has certain limitations, because only a few browsers need this polyfill at present, and if this polyfill is loaded in most browsers supporting the fetch method in order to be compatible with a few version browsers, unnecessary resource waste will be caused. SUMMARY
[0003] Therefore, the present application aims to provide a request sending method, device, equipment and storage medium, which not only effectively avoids the situation that all browsers download a polyfill in order to be compatible in the prior art, but also avoids the problem of request failure caused by initiating a request during polyfill downloading. The specific scheme is as follows:
[0004] In a first aspect, the present application provides a request sending method, comprising:
[0005] determining whether a current target browser supports a fetch method based on a preset function;
[0006] if the current target browser does not support the fetch method, triggering a download process of a polyfill code supporting the fetch method to load the polyfill code into the target browser;
[0007] in the download process, when a preset request initiation tool initiates an initial request, it is determined again whether the current target browser supports the fetch method, and if not, the initial request is intercepted and stored in a previously created request array;
[0008] after the download process ends, the initial request saved in the request array is converted into a corresponding Fetch request by the current target browser, and the Fetch request is sent to a corresponding destination.
[0009] Optionally, before the step of judging whether the target browser supports the fetch method again when the preset request initiation tool initiates the initial request in the downloading process, the method further comprises:
[0010] creating a corresponding request array variable in the header of the preset request initiation tool based on a preset code segment for adding a variable, so as to obtain the request array.
[0011] Optionally, the step of judging whether the target browser supports the fetch method based on a preset function comprises:
[0012] determining whether the target browser supports the fetch method by judging whether a window.fetch function exists in the target browser;
[0013] Correspondingly, the step of judging whether the target browser supports the fetch method again when the preset request initiation tool initiates the initial request in the downloading process comprises:
[0014] the step of determining whether the target browser supports the fetch method again when the preset request initiation tool initiates the initial request in the downloading process by judging whether a window.fetch function exists in the target browser.
[0015] Optionally, the step of intercepting the initial request and storing the initial request in the request array if not further comprises:
[0016] the step of creating a corresponding target arrow function in the request array based on a request function and a promise object obtained by performing a corresponding function modification operation on a target custom fetch function in the preset request initiation tool in advance, so as to complete a corresponding request sending operation based on the target arrow function after the downloading process ends.
[0017] Optionally, before the step of judging whether the target browser supports the fetch method based on a preset function, the method further comprises:
[0018] obtaining the request function by encapsulating a fragment for initiating a Fetch request in the target custom fetch function;
[0019] obtaining the promise object by invoking a Promise constructor based on the target custom fetch function and a new operator.
[0020] Optionally, the request method further comprises:
[0021] If the current target browser supports the fetch method, the request sending operation is completed by directly calling the request function and based on the callback function parameter corresponding to the promise object.
[0022] Optionally, the converting, by the current target browser, the initial request saved in the request array into a corresponding Fetch request comprises:
[0023] The initial request saved in the request array is converted into a corresponding Fetch request by the current target browser calling the request function based on the callback function parameter corresponding to the promise object, so as to complete the corresponding request sending operation.
[0024] In a second aspect, the present application provides a request sending device, comprising:
[0025] A first judgment module is configured to judge whether the current target browser supports the fetch method based on a preset function.
[0026] A code downloading module is configured to, if the current target browser does not support the fetch method, trigger a downloading process of polyfill code supporting the fetch method, so as to load the polyfill code into the target browser.
[0027] A request intercepting module is configured to, in the downloading process, judge again whether the current target browser supports the fetch method when a preset request initiating tool initiates an initial request, and if not, intercept the initial request and store it in a pre-created request array.
[0028] A request sending module is configured to, after the downloading process ends, convert the initial request saved in the request array into a corresponding Fetch request by the current target browser, and send the Fetch request to a corresponding destination.
[0029] In a third aspect, the present application provides an electronic device, comprising:
[0030] A memory is configured to save a computer program.
[0031] A processor is configured to execute the computer program to realize the steps of the aforementioned request sending method.
[0032] In a fourth aspect, the present application provides a computer readable storage medium for saving a computer program, which is executed by a processor to realize the steps of the aforementioned request sending method.
[0033] It can be seen that, in the present application, it is determined whether the current target browser supports the fetch method based on a preset function; if the current target browser does not support the fetch method, a download process of polyfill code supporting the fetch method is triggered to load the polyfill code into the target browser; in the download process, it is determined again whether the current target browser supports the fetch method when a preset request initiation tool initiates an initial request, and if not, the initial request is intercepted and stored in a previously created request array; after the download process ends, the initial request saved in the request array is converted into a corresponding Fetch request by the current target browser, and the Fetch request is sent to the corresponding destination. By triggering the corresponding polyfill code download process when the target browser is determined not to support the fetch method for the first time, and by determining that the target browser supports the fetch method to intercept the request during the download process, the present application not only effectively avoids the situation in the prior art where all browsers download polyfill for compatibility, but also effectively avoids the problem of request failure caused by initiating a request during polyfill download. BRIEF DESCRIPTION OF DRAWINGS
[0034] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the drawings needed in the embodiments or prior art description will be briefly introduced below. Obviously, the drawings in the following description are only embodiments of the present application, and those skilled in the art can obtain other drawings according to the provided drawings without creative labor.
[0035] Figure 1 A request sending method flowchart is provided for the present application;
[0036] Figure 2 A specific request sending flowchart is provided for the present application;
[0037] Figure 3 A specific request sending method flowchart is provided for the present application;
[0038] Figure 4 A request sending device structure diagram is provided for the present application;
[0039] Figure 5 An electronic device structure diagram is provided for the present application. DETAILED DESCRIPTION
[0040] With reference to the drawings of the embodiments of the present application, the technical solutions in the embodiments of the present application will be clearly and completely described. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments of the present application. Based on the embodiments of the present application, all the other embodiments obtained by a person of ordinary skill in the art without creative work are within the scope of protection of the present application.
[0041] In the prior technical solution, for the scene of initiating an HTTP request by a fetch method on a low-version browser end, a polyfill code file corresponding to the fetch method is packaged into a product by using babel during application construction to realize the compatibility of the fetch. However, the construction method has certain limitations, because currently only a small number of browsers need the polyfill, and if the polyfill is loaded in most browsers supporting the fetch method in order to be compatible with a small number of version browsers, unnecessary resource waste will be caused. Therefore, the application provides a request sending scheme, which not only effectively avoids the situation that all browsers download the polyfill in order to be compatible in the prior art, but also avoids the problem of request failure caused by initiating a request during polyfill downloading.
[0042] Referring to Figure 1 As shown in the figure, the application discloses a request sending method, comprising:
[0043] Step S11, judging whether the current target browser supports the fetch method based on a preset function.
[0044] In the embodiment, in combination with Figure 2 As shown in the figure, before the judgment, a request array needs to be created. In a specific embodiment, a corresponding request array variable is created in the head of the preset request initiation tool based on a preset code segment for adding a variable, so as to obtain the request array, and specifically, the request array can be represented as requestList. In this way, when the judgment result is no, the request array can be used to perform a corresponding operation. In addition, the preset function can be set by a user in advance.
[0045] Further, it needs to be understood that, before determining whether the current target browser supports the fetch method based on the preset function in the embodiment, the method can further include: obtaining the request function by encapsulating a fragment for initiating a Fetch request in a target custom fetch function in a preset request initiation tool; and obtaining the promise object by calling a Promise constructor function based on the target custom fetch function and a new operator. Here, the first letter is distinguished between a normal function (object) and a constructor function by capitalization. The target custom fetch function is a function that exists in the preset request initiation tool itself. In this step, the function is first exported from the preset request initiation tool and named as a customfetch function to obtain the target custom fetch function. The promise object can be obtained by executing the partial code shown below in the target custom fetch function.
[0046] return new Promise((resolve,reject)=>{ / / do judgment})
[0047] It can be understood that, in a specific implementation, if it is determined through the above judgment that the current target browser supports the fetch method, the corresponding request sending operation can be completed by directly calling the request function and based on a callback function parameter corresponding to the promise object. The callback function parameter corresponding to the promise object is a resolve callback function and a reject callback function, which respectively represent a callback function after the asynchronous operation is executed successfully and a callback function after the asynchronous operation is executed unsuccessfully. That is, in the process of executing the request sending, the request function sends a request by taking the corresponding request parameter and the resolve callback function and the reject callback function corresponding to the promise object as parameters. At the same time, the corresponding request result is returned to the target browser by calling the resolve callback function or the reject callback function. The partial code for sending a request by directly calling the request function can be as follows.
[0048] return request(resolve,reject,parameters)
[0049] Step S12, if the current target browser does not support the fetch method, a download process of polyfill code supporting the fetch method is triggered to load the polyfill code into the target browser.
[0050] It needs to be understood that in the embodiment, when the download process of the polyfill code supporting the fetch method is performed, specifically, the download process is performed based on a preset CDN (Content Delivery Network) storing the polyfill code, since the preset CDN allows the client including the browser to obtain the required resources from the nearest server, so as to improve the code download speed.
[0051] In the download process, when the initial request is initiated by the preset request initiation tool, it is judged again whether the target browser currently supports the fetch method, and if not, the initial request is intercepted and stored in the request array created in advance.
[0052] In the embodiment, in combination with Figure 2 As shown in the figure, in the download process, considering that it cannot be guaranteed that the preset request initiation tool does not initiate a request, therefore, in order to avoid the problem of request failure caused by initiating a request during polyfill download, the initial request initiated by the preset request initiation tool needs to be saved in the request array created in advance when the download process is not completed, so as to send the initial request after the download process is completed.
[0053] Further, in the embodiment, the if not, the initial request is intercepted and stored in the request array created in advance, specifically, can further include: by calling the push method of the request array variable, and based on the request function obtained by performing the corresponding function modification operation on the target custom fetch function in the preset request initiation tool in advance and the promise object, a corresponding target arrow function is created in the request array, so as to complete the corresponding request sending operation based on the target arrow function after the download process is completed. The part of code for calling the request function through the target arrow function to send a request later can be as follows.
[0054] requestList.push(()={return request(resolve, reject, parameters)})
[0055] Step S14, when the download process is completed, the initial request saved in the request array is converted into a corresponding Fetch request by the target browser currently, and the Fetch request is sent to the corresponding destination.
[0056] Specifically, in combination with Figure 2As shown, when the download process ends, that is, when a download completion event for the polyfill is listened to, a corresponding request initiation process is performed.
[0057] It needs to be understood that in the embodiment, the conversion of the initial request saved in the request array into a corresponding Fetch request by the current target browser can specifically include: the initial request saved in the request array is converted into a corresponding Fetch request by the current target browser calling the request function using the target arrow function and based on the callback function parameter corresponding to the promise object, so as to complete the request sending operation. The destination can be understood as a corresponding server. In the process of sending the initial request saved in the request array, considering that the number of saved initial requests can be more than one, when the number of initial requests is more than one, the request sending needs to be performed one by one.
[0058] It can be seen that in the embodiment of the application, it is determined whether the current target browser supports the fetch method based on a preset function; if the current target browser does not support the fetch method, a download process of polyfill code supporting the fetch method is triggered to load the polyfill code into the target browser; in the download process, it is determined again whether the current target browser supports the fetch method when a preset request initiation tool initiates an initial request, and if not, the initial request is intercepted and stored in a request array created in advance; after the download process ends, the initial request saved in the request array is converted into a corresponding Fetch request by the current target browser, and the Fetch request is sent to a corresponding destination. By triggering the download process of the corresponding polyfill code when it is determined for the first time that the target browser does not support the fetch method, and by determining that the target browser supports the fetch method to intercept the request during the download process, the problem of request failure caused by initiating a request during polyfill download can be effectively avoided, and the situation that all browsers download polyfill for compatibility in the prior art can be effectively avoided.
[0059] Referring to Figure 3 As shown, the embodiment of the application discloses a request sending method, comprising:
[0060] Step S21, it is determined whether the target browser supports the fetch method by judging whether the window.fetch function exists in the current target browser.
[0061] In this embodiment, it can be determined whether the target browser supports the Fetch method by directly judging whether window.fetch exists. In one specific implementation, the determination can be implemented by the following partial code.
[0062] if(window.fetch){ / / exists} or if(!window.fetch){ / / does not exist}
[0063] In step S22, if the target browser does not support the fetch method, a download process of polyfill code supporting the fetch method is triggered to load the polyfill code into the target browser.
[0064] In step S23, in the download process, whether the target browser supports the fetch method is determined again by judging whether the window.fetch function exists in the target browser when a preset request initiation tool initiates an initial request. If not, the initial request is intercepted and stored in a pre-created request array.
[0065] In step S24, after the download process ends, the initial request saved in the request array is converted into a corresponding Fetch request by the target browser, and the Fetch request is sent to a corresponding destination.
[0066] The specific process of steps S22 to S24 can refer to the corresponding content disclosed in the foregoing embodiments, and will not be described here.
[0067] It can be seen that, in the embodiment of the application, whether the target browser supports the fetch method is determined by judging whether the window.fetch function exists in the current target browser; if the current target browser does not support the fetch method, a download process of polyfill code supporting the fetch method is triggered to load the polyfill code into the target browser; in the download process, whether the target browser supports the fetch method is determined again by judging whether the window.fetch function exists in the current target browser when the initial request is initiated by the preset request initiation tool, and if not, the initial request is intercepted and stored in the pre-created request array; after the download process ends, the initial request saved in the request array is converted into a corresponding Fetch request by the current target browser, and the Fetch request is sent to the corresponding destination. By triggering the corresponding polyfill code download process when the target browser is determined not to support the fetch method based on the window.fetch function for the first time, and determining again that the target browser supports the fetch method based on the window.fetch function during the download process, the application can effectively avoid the situation that all browsers download polyfill in order to be compatible in the prior art, and can also effectively avoid the problem of request failure caused by initiating a request during polyfill download.
[0068] Referring to Figure 4 The embodiment of the application also discloses a request sending device, which comprises:
[0069] The first judgment module 11 is used for judging whether the current target browser supports the fetch method based on a preset function;
[0070] The code download module 12 is used for triggering a download process of polyfill code supporting the fetch method to load the polyfill code into the target browser if the current target browser does not support the fetch method;
[0071] The request interception module 13 is used for judging again whether the current target browser supports the fetch method when the initial request is initiated by the preset request initiation tool in the download process, and if not, the initial request is intercepted and stored in the pre-created request array;
[0072] The request sending module 14 is configured to, after the downloading process ends, convert the initial request saved in the request array into a corresponding Fetch request through the current target browser, and send the Fetch request to a corresponding destination.
[0073] The more specific working processes of the above modules can refer to the corresponding contents disclosed in the foregoing embodiments, and will not be described here.
[0074] It can be seen that, in the present application, it is determined whether the current target browser supports the fetch method based on a preset function; if the current target browser does not support the fetch method, a downloading process of polyfill code supporting the fetch method is triggered to load the polyfill code into the target browser; in the downloading process, it is determined again whether the current target browser supports the fetch method when the initial request is initiated by the preset request initiation tool, and if not, the initial request is intercepted and stored in the request array created in advance; after the downloading process ends, the initial request saved in the request array is converted into a corresponding Fetch request through the current target browser, and the Fetch request is sent to a corresponding destination. By triggering the downloading process of the corresponding polyfill code when it is determined for the first time that the target browser does not support the fetch method, and by determining that the target browser supports the fetch method to intercept the request during the downloading process, the present application can not only effectively avoid the situation that all browsers download polyfill in order to be compatible in the prior art, but also effectively avoid the problem of request failure caused by initiating a request during polyfill downloading.
[0075] In some specific embodiments, the request sending device can further include:
[0076] The array variable creation unit is configured to create a corresponding request array variable in the header of the preset request initiation tool based on a preset code segment for adding a variable, so as to obtain the request array.
[0077] In some specific embodiments, the first determination module 11 can include:
[0078] The first determination unit is configured to determine whether the target browser supports the fetch method by judging whether a window.fetch function exists in the current target browser.
[0079] Correspondingly, the request interception module 13 includes:
[0080] The second judging unit is configured to determine whether the target browser supports the fetch method again by judging whether the window.fetch function exists in the target browser when the initial request is initiated by the preset request initiation tool in the downloading process.
[0081] In some embodiments, the request interception module 13 can further include:
[0082] The target arrow function creating unit is configured to create a corresponding target arrow function in the request array based on a request function obtained by performing a corresponding function modification operation on the target custom fetch function in the preset request initiation tool and a promise object, by calling a push method of the request array variable, so as to complete a corresponding request sending operation based on the target arrow function after the downloading process ends.
[0083] In some embodiments, the request sending apparatus can further include:
[0084] The request function determining unit is configured to obtain the request function by encapsulating a fragment for initiating a Fetch request in the target custom fetch function.
[0085] The promise object obtaining unit is configured to obtain the promise object by calling a Promise constructor based on the target custom fetch function and a new operator.
[0086] In some embodiments, the request sending apparatus can further include:
[0087] The first request sending unit is configured to complete a corresponding request sending operation by directly calling the request function and based on a callback function parameter corresponding to the promise object if the target browser currently supports the fetch method.
[0088] In some embodiments, the request sending apparatus can include:
[0089] The second function request sending unit is configured to convert the initial request saved in the request array into a corresponding Fetch request to complete a corresponding request sending operation by calling the request function using the target arrow function and based on the callback function parameter corresponding to the promise object.
[0090] Further, the embodiments of the present application also disclose an electronic device, Figure 5is a structural diagram of an electronic device 20 according to an exemplary embodiment, and the content in the figure should not be considered as any limitation on the use range of the present application.
[0091] Figure 5 A structural diagram of an electronic device 20 is provided in the present embodiment. The electronic device 20 can specifically include at least one processor 21, at least one memory 22, a power supply 23, a communication interface 24, an input / output interface 25, and a communication bus 26. The memory 22 is configured to store a computer program, which is loaded and executed by the processor 21 to implement the related steps in the request sending method disclosed in any of the preceding embodiments. In addition, the electronic device 20 in the present embodiment can be specifically an electronic computer.
[0092] In the present embodiment, the power supply 23 is configured to provide operating voltage for each hardware device on the electronic device 20; the communication interface 24 can create a data transmission channel between the electronic device 20 and external devices, and the communication protocol followed by the communication interface 24 can be any communication protocol applicable to the technical solution of the present application, which is not specifically limited herein; the input / output interface 25 is configured to obtain external input data or output data to the outside, and the specific interface type can be selected according to the specific application needs, which is not specifically limited herein.
[0093] In addition, the memory 22 as a carrier for resource storage can be a read-only memory, a random access memory, a magnetic disk, or an optical disk, etc., and the resources stored thereon can include an operating system 221, a computer program 222, etc., and the storage mode can be temporary storage or permanent storage.
[0094] The operating system 221 is configured to manage and control each hardware device on the electronic device 20 and the computer program 222, and can be Windows Server, Netware, Unix, Linux, etc. The computer program 222 can further include computer programs for completing other specific work in addition to the computer program for completing the request sending method executed by the electronic device 20 disclosed in any of the preceding embodiments.
[0095] Further, the present application further discloses a computer readable storage medium for storing a computer program; wherein the computer program is executed by a processor to implement the request sending method disclosed above. The specific steps of the method can refer to the corresponding content disclosed in the preceding embodiments, which will not be repeated here.
[0096] The various embodiments described in the specification are progressive in nature, and each embodiment highlights the differences from other embodiments. The same or similar parts among the various embodiments can be mutually referred to. For the apparatus disclosed in the embodiments, since it corresponds to the method disclosed in the embodiments, the description is relatively simple, and the relevant parts can be referred to the method part.
[0097] Those skilled in the art will further appreciate that the individual steps of the examples described in connection with the embodiments disclosed herein can be embodied in electronic hardware, computer software, or combinations of both. The various examples have been described in relation to the described embodiments, as a means of generalizing the interchangeability of hardware and software under the principles mentioned above. The particular implementation of an individual example in either hardware or software can be determined by the particular application and design constraints imposed on the overall system. Skilled artisans will appreciate that the principles described herein can be practiced in a variety of system environments, and that the described implementations are merely examples and not intended to limit the scope of the application.
[0098] The steps of a method or algorithm described in connection with the embodiments disclosed herein can be embodied directly in hardware, in a software module executed by a processor, or in a combination of the two. A software module can reside in random access memory (RAM), flash memory, read-only memory (ROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM), registers, hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.
[0099] Finally, it needs to be pointed out that, in this document, the relationship terms such as first and second are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between the entities or operations. Moreover, the terms "include", "contain" or any other variants thereof are intended to cover non-exclusive inclusion, so that the process, method, article or device including a series of elements not only includes those elements, but also includes other elements not explicitly listed or inherent to such process, method, article or device. Without more limitations, the element defined by the statement "including a" does not exclude the presence of other identical elements in the process, method, article or device including the element.
[0100] The above describes the technical solutions provided by the present application in detail, and the principles and implementation manners of the present application are described by using specific examples. The above description of the embodiments is only to help understand the method and core idea of the present application; at the same time, for those skilled in the art, according to the idea of the present application, the specific implementation manner and application range can be changed, and the above description of the specification should not be understood as limiting the present application.
Claims
1. A request-to-send method, characterized in that, The method comprises the following steps: determining whether the current target browser supports the fetch method based on a preset function; if the current target browser does not support the fetch method, triggering a download process of polyfill code supporting the fetch method to load the polyfill code into the target browser; in the download process, when a preset request initiation tool initiates an initial request, determining again whether the current target browser supports the fetch method, and if not, intercepting the initial request and storing it in a previously created request array; after the download process ends, converting the initial request saved in the request array into a corresponding Fetch request through the current target browser, and sending the Fetch request to the corresponding destination; wherein, if not, intercepting the initial request and storing it in a previously created request array, further comprising: by calling the push method of the request array variable, and based on the request function obtained by previously modifying the target custom fetch function in the preset request initiation tool and the promise object in the request array, creating a corresponding target arrow function to complete the corresponding request sending operation based on the target arrow function after the download process ends; the triggering of the download process of the polyfill code supporting the fetch method comprises: the download process of the polyfill code supporting the fetch method is based on a preset content distribution network storing the polyfill code to execute the download process; when the download completion event of the polyfill is listened to, it is determined that the download process has ended. Before the step of determining again whether the current target browser supports the fetch method when the preset request initiation tool initiates an initial request in the download process, the method further comprises the following steps:
2. The request-to-send method of claim 1, wherein, based on the preset code segment for adding variables, a corresponding request array variable is created in the header of the preset request initiation tool to obtain the request array. The step of determining whether the current target browser supports the fetch method based on a preset function comprises:
3. The request-to-send method of claim 1, wherein, determining whether the target browser supports the fetch method by judging whether the window.fetch function exists in the current target browser; correspondingly, the step of determining again whether the current target browser supports the fetch method when the preset request initiation tool initiates an initial request in the download process comprises: in the download process, when the preset request initiation tool initiates an initial request, it is determined again whether the target browser supports the fetch method by judging whether the window.fetch function exists in the current target browser. Before the step of determining whether the current target browser supports the fetch method based on a preset function, the method further comprises the following steps:
4. The request-to-send method of claim 1, wherein, obtaining the request function by encapsulating the fragment for initiating the Fetch request in the target custom fetch function; The promise object is obtained by calling a Promise constructor based on the target custom fetch function and a new operator.
5. The request-to-send method of claim 4, wherein, Further comprising: If the current target browser supports the fetch method, the corresponding request sending operation is completed by directly calling the request function and based on the callback function parameter corresponding to the promise object.
6. The request-to-send method of claim 5, wherein, The initial request saved in the request array is converted into a corresponding Fetch request by the current target browser, including: The initial request saved in the request array is converted into a corresponding Fetch request by the current target browser using the target arrow function to call the request function and based on the callback function parameter corresponding to the promise object, to complete the corresponding request sending operation.
7. A request-to-send device, characterized in that Including: The first judgment module is used for judging whether the current target browser supports the fetch method based on a preset function; The code download module is used for triggering the download process of the polyfill code supporting the fetch method if the current target browser does not support the fetch method, so as to load the polyfill code into the target browser. The request interception module is used for judging whether the current target browser supports the fetch method again when the initial request is initiated by the preset request initiation tool in the download process, and if not, the initial request is intercepted and stored in the request array created in advance. The request sending module is used for converting the initial request saved in the request array into a corresponding Fetch request by the current target browser after the download process ends, and sending the Fetch request to the corresponding destination. The request sending device further comprises: The target arrow function creation unit is used for creating a corresponding target arrow function in the request array based on the request function obtained by modifying the target custom fetch function in the preset request initiation tool and the promise object, so as to complete the corresponding request sending operation based on the target arrow function after the download process ends. The code download module comprises: The download process execution unit is used for executing the download process of the polyfill code supporting the fetch method based on the preset content distribution network storing the polyfill code. The request sending module comprises: The event listening unit is used for determining that the download process has ended when the download completion event of the polyfill is listened to.
8. An electronic device, comprising: Including: The memory is used for saving the computer program; The processor is used for executing the computer program to realize the request sending method of any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that, The computer program is used for saving the computer program, which is executed by the processor to realize the request sending method of any one of claims 1 to 6.
Citation Information
Patent Citations
Webpage loading method and device, computer readable storage medium and computer equipment
CN112214703A