Static resource acquisition methods, devices, electronic equipment and storage media

By determining the storage environment and using the resource call code package to obtain static resources, the problem of inconsistent static resource acquisition methods under different storage environments is solved, achieving efficient resource acquisition and reducing system hardware and software overhead.

CN115268849BActive Publication Date: 2026-11-17BEIJING DAJIA INTERNET INFORMATION TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202210856553.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-07-20
Publication Date
2026-11-17
Estimated Expiration
2042-07-20

AI Technical Summary

Technical Problem

In existing technologies, due to the differences in the storage location and file specifications of static resources in different storage environments, different acquisition techniques need to be developed, which increases the system's hardware and software overhead.

Method used

By determining the storage environment of the target static resource, selecting the appropriate resource transfer object, and using the resource call code package to obtain the static resource, the same method can be used to obtain static resources in different storage environments.

Benefits of technology

It saves on the system hardware and software overhead required for acquiring static resources for different storage environments and improves acquisition efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115268849B_ABST
    Figure CN115268849B_ABST
Patent Text Reader

Abstract

This disclosure relates to a method, apparatus, electronic device, and storage medium for acquiring static resources, belonging to the field of computer technology. The static resource acquisition method includes: determining the storage environment of the target static resource to be acquired; determining a selected resource transfer object corresponding to the storage environment from a preset first resource transfer object and a second resource transfer object; requesting the acquisition of the target static resource from the selected resource transfer object and acquiring a resource call code package in response from the selected resource transfer object; and acquiring the target static resource using the resource call code package. This disclosure enables the acquisition of target static resources in different storage environments using the same acquisition method, saving the system hardware and software overhead of acquiring static resources in different storage environments.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This disclosure relates to the field of computer technology, and in particular to a method, apparatus, electronic device, and storage medium for obtaining static resources. Background Technology

[0002] With the separation of front-end and back-end development, a Node.js middleware layer has been introduced between them. This middleware layer enables Server-Side Rendering (SSR) of static resources between the front-end and back-end, and it can utilize static resource files from different storage environments. However, the storage location and file specifications of static resources differ across these environments; for example, static resources in development environments are stored in memory, while those in production environments are persisted to disk.

[0003] In related technologies, different acquisition techniques are often developed for static resources in different storage environments in order to acquire static resources in different storage environments. However, this approach increases the system's hardware and software overhead. Summary of the Invention

[0004] This disclosure provides a static resource acquisition method, apparatus, electronic device, and storage medium to at least solve the technical problem of increased system hardware and software overhead in related technologies.

[0005] According to one aspect of the embodiments of this disclosure, a method for obtaining static resources is provided, including:

[0006] Determine the storage environment of the target static resource to be acquired;

[0007] A selected resource transfer object corresponding to the storage environment is determined from a preset first resource transfer object and a second resource transfer object; wherein, the first resource transfer object is a resource transfer object used to acquire static resources in the development environment, and the second resource transfer object is a resource transfer object used to acquire static resources in the production environment;

[0008] Request the selected resource delivery object to obtain the target static resource, and obtain the resource invocation code package in response to the selected resource delivery object. The resource invocation code package is used to extract the static resource from the storage environment corresponding to the selected resource delivery object.

[0009] The target static resource is obtained by using the resource call code package.

[0010] In one possible implementation, before determining the storage environment of the target static resource to be acquired, the static resource acquisition method further includes:

[0011] The webpack bundling tool is used to bundle and compile the static resources in the development environment, and a resource call code package associated with the static resources is generated.

[0012] The webpack-dev-middle middleware is used to store static resources in the development environment in the memory stream of the development environment;

[0013] The resource call code package is attached to the first resource transfer object.

[0014] In one possible implementation, the static resource acquisition method further includes:

[0015] The memory stream is hot-updated using the webpack-hot-client middleware.

[0016] In one possible implementation, the static resource acquisition method further includes:

[0017] Using a memory file system, the memory stream is created for the static resource in the memory space of the development environment.

[0018] In one possible implementation, static resources in the production environment are stored in the disk space of the production environment;

[0019] Before determining the storage environment of the target static resource to be acquired, the static resource acquisition method further includes:

[0020] Using the koa-static-middleware, the resource call code package associated with the static resources in the production environment is mounted on the second resource transfer object.

[0021] In one possible implementation, the resource invocation code package includes at least one of an fs object, a serverfs object, and the mrequire method;

[0022] The step of using the resource call code package to obtain the target static resource includes:

[0023] The target static resource is obtained by invoking at least one of the following: the fs object, the serverfs object, and the mrequire method.

[0024] According to another aspect of the embodiments of this disclosure, a static resource acquisition apparatus is provided, comprising:

[0025] The storage environment determination module is configured to determine the storage environment of the target static resource to be acquired;

[0026] The resource transfer object determination module is configured to determine a selected resource transfer object corresponding to the storage environment from a preset first resource transfer object and a second resource transfer object; wherein, the first resource transfer object is a resource transfer object used to obtain static resources in the development environment, and the second resource transfer object is a resource transfer object used to obtain static resources in the production environment;

[0027] The resource invocation code package acquisition module is configured to execute a request to the selected resource delivery object to obtain the target static resource, and to obtain the resource invocation code package in response to the selected resource delivery object. The resource invocation code package is used to extract the static resource from the storage environment corresponding to the selected resource delivery object.

[0028] The resource acquisition module is configured to execute the resource call code package to acquire the target static resource.

[0029] In one possible implementation, the static resource acquisition device further includes:

[0030] The static resource generation module is configured to use the webpack bundling tool to bundle and compile static resources in the development environment, and generate resource call code packages associated with the static resources;

[0031] The static resource storage module is configured to use the webpack-dev-middle middleware to store static resources in the development environment in the memory stream of the development environment;

[0032] The first resource invocation code package mounting module is configured to mount the resource invocation code package to the first resource transfer object.

[0033] In one possible implementation, the static resource acquisition device further includes:

[0034] The memory stream hot update module is configured to perform hot updates on the memory stream using the webpack-hot-client middleware.

[0035] In one possible implementation, the static resource acquisition device further includes:

[0036] The memory stream creation module is configured to utilize the memory file system to create the memory stream for the static resource in the memory space of the development environment.

[0037] In one possible implementation, static resources in the production environment are stored in the disk space of the production environment;

[0038] The static resource acquisition device further includes:

[0039] The second resource invocation code package mounting module is configured to use the koa-static-middleware middleware to mount the resource invocation code package associated with the static resource in the production environment to the second resource delivery object.

[0040] In one possible implementation, the resource invocation code package includes at least one of an fs object, a serverfs object, and the mrequire method;

[0041] The resource acquisition module is further configured to execute:

[0042] The target static resource is obtained by invoking at least one of the following: the fs object, the serverfs object, and the mrequire method.

[0043] According to another aspect of the embodiments of this disclosure, an electronic device is provided, comprising:

[0044] processor;

[0045] Memory for storing the executable instructions of the processor;

[0046] The processor is configured to execute the executable instructions to implement the static resource acquisition method as described in any of the above embodiments.

[0047] According to another aspect of the present disclosure, a computer-readable storage medium is provided, which, when at least one instruction in the computer-readable storage medium is executed by a processor of an electronic device, enables the electronic device to implement the static resource acquisition method described in any of the above embodiments.

[0048] According to another aspect of the present disclosure, a computer program product is provided, including a computer program that, when executed by a processor, implements the static resource acquisition method described in any of the above embodiments.

[0049] The technical solutions provided by the embodiments of this disclosure have at least the following beneficial effects:

[0050] The static resource acquisition method, apparatus, electronic device, and storage medium of this disclosure, after determining the storage environment of the target static resource to be acquired, request the acquisition of the target static resource from a selected resource delivery object corresponding to the determined storage environment, and then acquire the target static resource using the resource call code package responded by the selected resource delivery object. In this disclosure, for different storage environments of the target static resource, only the same method is needed to acquire the target static resource, that is, request the acquisition of the target static resource from the selected resource delivery object corresponding to the determined storage environment, receive the resource call code package responded by the selected resource delivery object, and acquire the target static resource using the received resource call code package. Therefore, this disclosure realizes the acquisition of target static resources in different storage environments using the same acquisition method, saving the system hardware and software overhead of the technical means of acquiring static resources in different storage environments.

[0051] It should be understood that the above general description and the following detailed description are exemplary and explanatory only, and are not intended to limit this disclosure. Attached Figure Description

[0052] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this disclosure and, together with the description, serve to explain the principles of this disclosure, and are not intended to unduly limit this disclosure.

[0053] Figure 1 This is a flowchart illustrating a static resource acquisition method according to an illustrative embodiment;

[0054] Figure 2 This is a flowchart illustrating configuration in a development environment according to an illustrative embodiment;

[0055] Figure 3 This is a flowchart illustrating an application scenario of a static resource acquisition method according to an illustrative embodiment;

[0056] Figure 4 This is a block diagram illustrating the logic structure of a static resource acquisition device according to an illustrative embodiment;

[0057] Figure 5 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this disclosure. Detailed Implementation

[0058] To enable those skilled in the art to better understand the technical solutions of this disclosure, the technical solutions in the embodiments of this disclosure will be clearly and completely described below with reference to the accompanying drawings.

[0059] It should be noted that the terms "first," "second," etc., used in the specification, claims, and accompanying drawings of this disclosure are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this disclosure described herein can be implemented in orders other than those illustrated or described herein. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this disclosure. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this disclosure as detailed in the appended claims.

[0060] It should be noted that the user information involved in this disclosure (including but not limited to user device information, user personal information, etc.) is all information authorized by the user or fully authorized by all parties.

[0061] When using Node as a middleware layer in the front-end to handle SSR server-side rendering of HTML, the static resources compiled in the development environment and the static resources in the production environment are stored in different ways. Therefore, the SSR of the same Node middleware layer cannot be compatible with the static resources of both the development and production environments at the same time.

[0062] The first existing solution to this problem is to use two sets of code for the development and production environments, maintaining two sets of SSR-related code for the development and production environments respectively. This approach is costly and prone to errors.

[0063] The second existing solution to this problem is to share a set of code between the development and production environments, and to output the compilation results of the development environment to the disk in the same way as the production environment. Although this approach can make the code of the same Node middleware SSR compatible with both the development and production environments, the development environment is slow to compile due to the need to frequently modify the code, which in turn affects development efficiency and user experience.

[0064] The third existing solution to this problem is to start two Node services, one for hot resource updates in the development environment and the other for SSR. This approach makes starting the Node services cumbersome and requires high-configuration hardware.

[0065] In view of this, the present disclosure provides a static resource acquisition method, apparatus, electronic device and storage medium, which use the same acquisition method to acquire target static resources in different storage environments, thereby saving the system hardware and software overhead of technical means to acquire static resources in different storage environments.

[0066] Figure 1 This is a flowchart illustrating a static resource acquisition method according to an illustrative embodiment. See also... Figure 1 As shown, this static resource acquisition method is applied to computer devices. The following explanation uses a computer device as a server as an example.

[0067] Step 101: Determine the storage environment of the target static resource to be acquired;

[0068] Step 102: Determine the selected resource transfer object corresponding to the storage environment from the preset first resource transfer object and second resource transfer object; wherein, the first resource transfer object is the resource transfer object used to obtain static resources in the development environment, and the second resource transfer object is the resource transfer object used to obtain static resources in the production environment;

[0069] Step 103: Request the selected resource delivery object to obtain the target static resource, and obtain the resource invocation code package in response to the selected resource delivery object. The resource invocation code package is used to extract the static resource from the storage environment corresponding to the selected resource delivery object.

[0070] Step 104: Use the resource call code package to obtain the target static resource.

[0071] The static resource acquisition method of this disclosure, after determining the storage environment of the target static resource to be acquired, requests the acquisition of the target static resource from a selected resource delivery object corresponding to the determined storage environment, and then uses the resource call code package responded by the selected resource delivery object to acquire the target static resource. In this disclosure, for different storage environments of the target static resource, only the same method is needed to acquire the target static resource, that is, request the acquisition of the target static resource from the selected resource delivery object corresponding to the determined storage environment, receive the resource call code package responded by the selected resource delivery object, and use the received resource call code package to acquire the target static resource. Therefore, this disclosure realizes the acquisition of target static resources in different storage environments using the same acquisition method, saving the system hardware and software overhead of the technical means of acquiring static resources in different storage environments.

[0072] The static resource acquisition method of this disclosure can be applied to the server-side rendering of static resources in development and production environments by the Node middleware layer. Correspondingly, the storage environment determined in step 101 is either a development environment or a production environment. Generally, code in the development environment is designed for better readability, while code in the runtime environment is designed for faster execution. Therefore, the code formats in the development and runtime environments are also different. For example, code in the development environment may be obfuscated and compressed before being run online, resulting in a smaller code size without affecting code execution.

[0073] In some embodiments, the first resource transfer object in step 102 is a resource transfer object corresponding to the development environment, the second resource transfer object is a resource transfer object corresponding to the production environment, and the selected resource transfer object determined in step 102 is one of the first resource transfer object and the second resource transfer object.

[0074] In some embodiments, the first resource transfer object and the second resource transfer object can be ctx(context), where ctx is the context object. ctx can be applied to the development environment and the production environment as their external interface. In step 102, the first resource transfer object is, for example, the context object of the development environment, and the second resource transfer object is, for example, the context object of the production environment. The context object of the development environment is used to obtain static resources in the development environment, and the context object of the production environment is used to obtain static resources in the production environment.

[0075] In order to obtain static resources in the development environment, corresponding configuration is required in the development environment. In this case, the static resource acquisition method of this disclosure embodiment also includes a configuration process in the development environment. Figure 2 This is a flowchart illustrating configuration in a development environment according to an illustrative embodiment, such as... Figure 2 As shown, prior to step 101, the static resource acquisition method of this embodiment further includes the following steps 201 to 203.

[0076] Step 201: Use the webpack bundling tool to package and compile static resources in the development environment, and generate resource call code packages associated with the static resources.

[0077] Step 202: Use the webpack-dev-middle middleware to store static resources in the development environment in the development environment's memory stream;

[0078] Step 203: Mount the resource call code package to the first resource transfer object.

[0079] Webpack is a static module bundler for modern JavaScript applications. Webpack-dev-middleware is a middleware that handles the static resources bundled by Webpack. It stores the static resources bundled from the front-end code by Webpack in the development environment's memory stream. When using Webpack for file bundling, Webpack-dev-middleware writes the bundled files directly to memory instead of disk, thus saving write time in the development environment.

[0080] In one example, when the webpack bundling tool packages static resources, it obtains a compiler object. By calling this compiler object, the static resources in the development environment's memory stream can be obtained. Based on this, in some embodiments, the resource invocation code package in step 201, i.e., the resource invocation code package associated with the static resources in the development environment, can be the compiler object obtained when the webpack bundling tool packages the static resources. In step 203, the compiler object is attached to the first resource delivery object, that is, the compiler object is attached to the development environment's context object. Therefore, by obtaining the static resources of the development environment from the development environment's context object in step 103, the compiler object responded to by the development environment's context object can be obtained. Furthermore, by calling this compiler object in step 104, the static resources of the development environment can be obtained.

[0081] In some embodiments, when static resources are stored in the memory stream of the development environment, hot updates of the memory stream are also required. The static resource acquisition method of this disclosure may further include:

[0082] Use the webpack-hot-client middleware to perform hot updates on memory streams.

[0083] The webpack-hot-client middleware is a library used to implement webpack hot reloading.

[0084] In order to realize the creation of memory streams in the development environment, the static resource acquisition method of this disclosure embodiment further includes:

[0085] Memory File System is used to create memory streams for static resources in the memory space of the development environment.

[0086] In a production environment, static resources are stored in the production environment's disk space. To obtain the static resources stored in the disk space, prior to step 101, the static resource acquisition method of this embodiment further includes the following steps performed in the production environment:

[0087] By using the koa-static-middleware, the resource call code package associated with static resources in the production environment is mounted on the second resource pass object.

[0088] koa-static-middleware is a Koa middleware for responding to static resources, typically used in production environments. Koa is a web development framework based on Node.js, which is a JavaScript runtime environment based on the Chrome V8 engine. koa-static-middleware is a middleware for requesting static resources such as HTML, JS, CSS, JPG, and PNG files, and does not involve other processing steps.

[0089] In some embodiments, the resource retrieval package includes at least one of the following: an `fs` object, a `serverfs` object, and the `mrequire` method. In some embodiments, the `fs` object and `serverfs` object are specific to the production environment. In the production environment, the `koa-static-middleware` middleware can be used to directly obtain the `fs` object and `serverfs` object for retrieving static resources. After obtaining the `fs` object and `serverfs` object, calling the `fs` object or `serverfs` object will retrieve the static resources for the production environment. In some embodiments, `mrequire` is a custom method for executing JavaScript files, which can be called a JavaScript file execution method. It can execute JavaScript files in memory streams or on disk.

[0090] Here, fs can be called static resource file, serverfs can be called server-side static resource file, fs refers to static resource file in the case of CSR (Client Side Rendering), and serverfs refers to static resource file in the case of SSR.

[0091] As described above, the compiler object in the development environment is equivalent to the fs object and serverfs object in the production environment. In other words, the compiler object in the development environment can also be referred to as the fs object and serverfs object in the development environment.

[0092] Based on this, step 104, which utilizes the resource call code package to obtain the target static resource, further includes:

[0093] Obtain the target static resource by invoking the fs object, invoking the serverfs object, or executing the mrequire method.

[0094] Since the context object (ctx) can be integrated into the middleware of webpack and koa, it can serve as the interface between the development and production environments. The static resource acquisition method of this disclosure utilizes the context object and the resource call code package obtained by the middleware of webpack and koa. By attaching the resource call code package to the context object, after obtaining the resource call code package in response to the context object of the development or production environment, the static resources of the development or production environment can be obtained using the obtained resource call code package. This achieves the acquisition of target static resources in different storage environments using the same acquisition method.

[0095] In some embodiments, based on the context object, in step 103, requesting the target static resource from the selected resource delivery object can be implemented using ctx.request or ctx.req. Here, ctx.request is a request object encapsulated by the context object, and ctx.req is a native HTTP request object provided by the context object in Node.js.

[0096] In some embodiments, resource invocation packages are mounted to `ctx.state`. This allows the development environment's resource invocation package to be mounted to a first resource delivery object, and the production environment's resource invocation package to be mounted to a second resource delivery object. In the development environment, the `compiler` object, acting as both the `fs` and `serverfs` objects, is mounted to `ctx.state`. The `mrequire` method can be mounted to `ctx.state` through code. Thus, by responding to `ctx.request` or `ctx.req` in either the development or production environment, the resource invocation package mounted on `ctx.state` can be obtained.

[0097] All of the above-mentioned optional technical solutions can be combined in any way to form optional embodiments of this disclosure, and will not be described in detail here.

[0098] Figure 3 This is a flowchart illustrating an application scenario of a static resource acquisition method according to an illustrative embodiment. See also... Figure 3 As shown, the static resource acquisition method includes the following steps.

[0099] Step 301: In the development environment, call webpack to bundle and compile the written code, output static resources to the memory stream created by MemoryFileSystem, and mount the resource call code package in the development environment to ctx.state in the development environment. Use webpack-dev-middle middleware and webpack-hot-client middleware to achieve hot reloading.

[0100] The resource call package includes the compiler object (equivalent to the fs object and serverfs object) and the mrequire method in the development environment.

[0101] Step 302: In the production environment, based on the koa-static-middleware, mount the resource call code package in the production environment to ctx.state in the production environment.

[0102] The second page resources include the fs object, serverfs object, and mrequire method in the production environment.

[0103] Step 303: The SSR server determines the storage environment of the target static resource to be acquired. If the storage environment is a development environment, proceed to step 3041; if the storage environment is a production environment, proceed to step 3042.

[0104] Step 3041: Select the ctx in the development environment, and then proceed to step 305.

[0105] Step 3042: Select the production environment ctx as the selected ctx, and then proceed to step 305.

[0106] Step 305: Request the target static resource from the selected ctx and obtain the resource call code package in response from the selected ctx.

[0107] Specifically, the resource call code package that the selected ctx responds to is the resource call code package that is mounted on the ctx.state of the selected ctx. If the selected ctx is a ctx in the development environment, the obtained resource call code package is the resource call code that is mounted on the ctx.state of the development environment. If the selected ctx is a ctx in the production environment, the obtained resource call code package is the resource call code that is mounted on the ctx.state of the production environment.

[0108] Step 306: Use the resource call code package to obtain the target static resource.

[0109] Step 306 may include obtaining the target static resource by invoking the `fs` object and `serverfs` object in the resource retrieval package, and executing the `mrequire` method in the resource retrieval package. Specifically, if the resource retrieval package is in the development environment, the target static resource obtained using the resource retrieval package is a static resource in the development environment; if the resource retrieval package is in the production environment, the target static resource obtained using the resource retrieval package is a static resource in the production environment.

[0110] All of the above-mentioned optional technical solutions can be combined in any way to form optional embodiments of this disclosure, and will not be described in detail here.

[0111] Figure 4 This is a logical structure block diagram of a static resource acquisition device according to an illustrative embodiment. See also... Figure 4 As shown, the device includes a storage environment determination module 401, a resource transfer object determination module 402, a resource call code package acquisition module 403, and a resource acquisition module 404.

[0112] The storage environment determination module 401 is configured to determine the storage environment of the target static resource to be acquired.

[0113] The resource transfer object determination module 402 is configured to determine a selected resource transfer object corresponding to the storage environment from a preset first resource transfer object and a second resource transfer object; wherein the first resource transfer object is a resource transfer object used to obtain static resources in the development environment, and the second resource transfer object is a resource transfer object used to obtain static resources in the production environment.

[0114] The resource invocation code package acquisition module 403 is configured to execute a request to the selected resource delivery object to obtain the target static resource, and to obtain the resource invocation code package in response to the selected resource delivery object. The resource invocation code package is used to extract the static resource from the storage environment corresponding to the selected resource delivery object.

[0115] The resource acquisition module 404 is configured to execute a resource call code package to acquire the target static resource.

[0116] The static resource acquisition device of this disclosure, after determining the storage environment of the target static resource to be acquired, requests the target static resource from a selected resource delivery object corresponding to the determined storage environment, and then uses the resource call code package responded by the selected resource delivery object to acquire the target static resource. In this disclosure embodiment, for different storage environments of the target static resource, only the same method is needed to acquire the target static resource, that is, request the target static resource from the selected resource delivery object corresponding to the determined storage environment, receive the resource call code package responded by the selected resource delivery object, and use the received resource call code package to acquire the target static resource. Therefore, this disclosure embodiment realizes the acquisition of target static resources in different storage environments using the same acquisition method, saving the system hardware and software overhead of the technical means of acquiring static resources in different storage environments.

[0117] In some embodiments, the static resource acquisition device of this disclosure further includes a static resource generation module, a static resource storage module, and a first resource call code package mounting module.

[0118] The static resource generation module is configured to use the webpack bundling tool to package and compile static resources for the development environment, and generate resource call code packages associated with the static resources.

[0119] The static resource storage module is configured to use the webpack-dev-middle middleware to store static resources in the development environment in the development environment's memory stream.

[0120] The first resource invocation code package mounting module is configured to mount the resource invocation code package onto the first resource transfer object.

[0121] In some embodiments, the static resource acquisition apparatus of this disclosure further includes a memory stream hot update module, configured to perform hot updates on the memory stream using the webpack-hot-client middleware.

[0122] In some embodiments, the static resource acquisition apparatus of this disclosure further includes a memory stream creation module, configured to utilize a memory file system to create a memory stream for static resources in the memory space of the development environment.

[0123] In some embodiments, static resources in the production environment are stored on the production environment's disk space. The static resource acquisition apparatus of this disclosure further includes a second resource invocation code package mounting module, configured to utilize the koa-static-middleware middleware to mount the resource invocation code package associated with the static resources in the production environment onto a second resource transfer object.

[0124] In some embodiments, the resource invocation package includes at least one of an fs object, a serverfs object, and an mrequire method. The resource acquisition module 404 is further configured to acquire the target static resource by invoking the fs object, invoking the serverfs object, and executing the mrequire method.

[0125] All of the above-mentioned optional technical solutions can be combined in any way to form optional embodiments of this disclosure, and will not be described in detail here.

[0126] Regarding the static resource acquisition device in the above embodiments, the specific manner in which each unit performs its operation has been described in detail in the embodiments related to the static resource acquisition method, and will not be elaborated here.

[0127] It should be noted that the above embodiments are only examples of the division of the above functional modules. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above.

[0128] Figure 5 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this disclosure. In some embodiments, the electronic device is a server. The electronic device 500 can vary considerably due to different configurations or performance, and may include one or more Central Processing Units (CPUs) 501 and one or more memories 502, wherein the memory 502 stores at least one line of program code, which is loaded and executed by the processor 501 to implement the static resource acquisition method provided in the various embodiments described above. Of course, the electronic device 500 may also have wired or wireless network interfaces, a keyboard, and input / output interfaces for input and output. The electronic device 500 may also include other components for implementing device functions, which will not be elaborated here.

[0129] In an exemplary embodiment, a computer-readable storage medium including at least one instruction is also provided, such as a memory including at least one instruction, which can be executed by a processor in a computer device to complete the static resource acquisition method in the above embodiments.

[0130] Optionally, the aforementioned computer-readable storage medium may be a non-transitory computer-readable storage medium, such as ROM (Read-Only Memory), RAM (Random-Access Memory), CD-ROM (Compact Disc Read-Only Memory), magnetic tape, floppy disk, and optical data storage devices.

[0131] In an exemplary embodiment, a computer program product is also provided, including one or more instructions that can be executed by a processor of a computer device to perform the static resource acquisition method provided in the above embodiments.

[0132] Other embodiments of this disclosure will readily occur to those skilled in the art upon consideration of the specification and practice of the invention disclosed herein. This disclosure is intended to cover any variations, uses, or adaptations of this disclosure that follow the general principles of this disclosure and include common knowledge or customary techniques in the art not disclosed herein. The specification and examples are to be considered exemplary only, and the true scope and spirit of this disclosure are indicated by the following claims.

[0133] It should be understood that this disclosure is not limited to the precise structures described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from its scope. The scope of this disclosure is limited only by the appended claims.

Claims

1. A static resource acquisition method, characterized by, include: Determine the storage environment of the target static resource to be acquired; A selected resource transfer object corresponding to the storage environment is determined from a preset first resource transfer object and a second resource transfer object; wherein, the first resource transfer object is a resource transfer object used to obtain static resources in the development environment, the second resource transfer object is a resource transfer object used to obtain static resources in the production environment, and the first resource transfer object and the second resource transfer object are context objects; Request the selected resource delivery object to obtain the target static resource, and obtain the resource invocation code package in response to the selected resource delivery object. The resource invocation code package is used to extract the static resource from the storage environment corresponding to the selected resource delivery object. The resource invocation code package includes at least one of the following: an fs object, a serverfs object, and the mrequire method. Use the resource call code package to obtain the target static resource; The resource invocation code package of the development environment is attached to the state property of the first resource transfer object, and the resource invocation code package of the production environment is attached to the state property of the second resource transfer object.

2. The static resource acquisition method of claim 1, wherein, Before determining the storage environment of the target static resource to be acquired, the static resource acquisition method further includes: The webpack bundling tool is used to bundle and compile the static resources in the development environment, and a resource call code package associated with the static resources is generated. The webpack-dev-middle middleware is used to store static resources in the development environment in the memory stream of the development environment; The resource call code package is attached to the first resource transfer object.

3. The static resource acquisition method of claim 2, wherein, The static resource acquisition method further includes: The memory stream is hot-updated using the webpack-hot-client middleware.

4. The static resource acquisition method of claim 3, wherein, The static resource acquisition method further includes: Using a memory file system, the memory stream is created for the static resource in the memory space of the development environment.

5. The static resource acquisition method according to claim 1, characterized in that: Static resources in the production environment are stored in the disk space of the production environment; Before determining the storage environment of the target static resource to be acquired, the static resource acquisition method further includes: Using the koa-static-middleware, the resource call code package associated with the static resources in the production environment is mounted on the second resource transfer object.

6. The static resource acquisition method according to claim 1, characterized in that: The step of using the resource call code package to obtain the target static resource includes: The target static resource is obtained by invoking at least one of the following: the fs object, the serverfs object, and the mrequire method.

7. A static resource acquisition apparatus, characterized by comprising: include: The storage environment determination module is configured to determine the storage environment of the target static resource to be acquired; The resource transfer object determination module is configured to determine a selected resource transfer object corresponding to the storage environment from a preset first resource transfer object and a second resource transfer object; wherein, the first resource transfer object is a resource transfer object used to obtain static resources in the development environment, the second resource transfer object is a resource transfer object used to obtain static resources in the production environment, and the first resource transfer object and the second resource transfer object are context objects; The resource invocation code package acquisition module is configured to execute a request to the selected resource delivery object to obtain the target static resource, and obtain the resource invocation code package in response to the selected resource delivery object. The resource invocation code package is used to extract the static resource from the storage environment corresponding to the selected resource delivery object. The resource invocation code package includes at least one of the following: an fs object, a serverfs object, and the mrequire method. The resource acquisition module is configured to execute a code package that calls the resource to acquire the target static resource; The resource invocation code package of the development environment is attached to the state property of the first resource transfer object, and the resource invocation code package of the production environment is attached to the state property of the second resource transfer object.

8. The static resource acquisition apparatus according to claim 7, characterized by The static resource acquisition device further includes: The static resource generation module is configured to use the webpack bundling tool to bundle and compile static resources in the development environment, and generate resource call code packages associated with the static resources; The static resource storage module is configured to use the webpack-dev-middle middleware to store static resources in the development environment in the memory stream of the development environment; The first resource invocation code package mounting module is configured to mount the resource invocation code package to the first resource transfer object.

9. The static resource acquisition apparatus according to claim 8, characterized by The static resource acquisition device further includes: The memory stream hot update module is configured to perform hot updates on the memory stream using the webpack-hot-client middleware.

10. The static resource acquisition apparatus according to claim 9, wherein The static resource acquisition device further includes: The memory stream creation module is configured to utilize the memory file system to create the memory stream for the static resource in the memory space of the development environment.

11. The static resource acquisition device according to claim 7, characterized in that: Static resources in the production environment are stored in the disk space of the production environment; The static resource acquisition device further includes: The second resource invocation code package mounting module is configured to use the koa-static-middleware middleware to mount the resource invocation code package associated with the static resource in the production environment to the second resource delivery object.

12. The static resource acquisition device according to claim 7, characterized in that: The resource acquisition module is further configured to execute: The target static resource is obtained by invoking at least one of the following: the fs object, the serverfs object, and the mrequire method.

13. An electronic device, characterized in that, include: processor; Memory for storing the executable instructions of the processor; The processor is configured to execute the executable instructions to implement the static resource acquisition method as described in any one of claims 1 to 6.

14. A computer-readable storage medium, characterized in that, When at least one instruction in the computer-readable storage medium is executed by the processor of the electronic device, the electronic device is able to implement the static resource acquisition method as described in any one of claims 1 to 6.

15. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by the processor, it implements the static resource acquisition method as described in any one of claims 1 to 6.