Picture loading method and device of browser, computing equipment and storage medium
Patent Information
- Application Number
- CN202411189955.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-27
- Publication Date
- 2024-11-22
- Estimated Expiration
- Not applicable · inactive patent
Smart Images

Figure CN119003034A_ABST
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the field of Internet technology, and specifically to a method, apparatus, computing device, and storage medium for loading images in a browser. Background Art
[0002] With the rapid development of the Internet, more and more users use electronic devices to browse pages to obtain news information, product introduction information, event information, etc. In order to attract users to view the page, pictures are usually set on the page to present rich page content in the form of pictures. The size of the picture file affects the speed of picture loading, which in turn affects the speed of page rendering. While maintaining the same picture quality, the file sizes of pictures in different formats are different. From the perspective of performance optimization, while maintaining the same picture quality, the smaller the picture file, the better the page performance, so a picture degradation plan is formulated. The picture degradation plan is to give priority to picture files with smaller file sizes in the page.
[0003] In the prior art, the picture tag in HTML is usually used to implement the picture degradation solution. The picture tag may contain source elements and picture (img) elements. The source element is used to match different devices and reference different picture sources. If there is no match, the URL in the src attribute of the picture element may be selected to load the picture. However, if the browser does not support the format of the picture file with a smaller size, the browser will still request the picture file of its format in turn during the degradation process, resulting in unnecessary traffic consumption. In addition, some browsers do not support the picture tag, which makes the solution inapplicable and has the problem of poor applicability. Summary of the invention
[0004] In view of the above problems, the present application proposes a browser image loading method, apparatus, computing device and storage medium to solve the following problems: the existing image degradation processing method has unnecessary traffic consumption and poor applicability.
[0005] According to one aspect of an embodiment of the present application, a method for loading an image in a browser is provided, comprising:
[0006] Identifying a target image format supported by the browser through a preset programming language; wherein the target image format refers to an image format with the smallest image file size among multiple image formats supported by the browser while maintaining a preset image quality;
[0007] Add target classes corresponding to the target image format to the subject label;
[0008] Use the style selector to load the image file in the target image format according to the target class.
[0009] Furthermore, identifying the target image format supported by the browser through the preset programming language further includes:
[0010] Determining whether the browser supports the first image format by using a preset programming language;
[0011] If the first image format is supported, the first image format is used as the target image format; if the first image format is not supported, whether the browser supports the second image format is determined by a preset programming language;
[0012] If the second picture format is supported, the second picture format is used as the target picture format; if the second picture format is not supported, the third picture format is used as the target picture format;
[0013] Wherein, while maintaining the preset image quality, the image file size of the first image format is smaller than the image file size of the second image format, and the image file size of the second image format is smaller than the image file size of the third image format.
[0014] Furthermore, the first image format is avif format;
[0015] Determining whether the browser supports the first image format by using a preset programming language further includes:
[0016] Determine whether there is a method for creating a picture bitmap by using a preset programming language;
[0017] If there is a method for creating a picture bitmap, a request is made to obtain a picture file of a first picture format in a preset encoding method. When the request is successful, a binary large object is read from the response, and the binary large object is processed using the method for creating a picture bitmap to obtain a corresponding commitment object. If the asynchronous operation of the commitment object is successful, it is determined that the first picture format is supported.
[0018] If there is no method for creating a picture bitmap or the asynchronous operation of the promised object fails, it is determined that the first picture format is not supported.
[0019] Furthermore, the second picture format is a webp format;
[0020] Determining whether the browser supports the second image format by using a preset programming language further includes:
[0021] Creating a canvas tag using a preset programming language, converting the content of the canvas tag into a string, and detecting whether the string contains a preset field corresponding to the second image format;
[0022] If the preset field is included, it is determined that the second image format is supported;
[0023] If the preset field is not included, it is determined that the second image format is not supported.
[0024] Furthermore, the third image format includes: jpeg format or png format.
[0025] Furthermore, the preset programming language is JavaScript language.
[0026] According to another aspect of an embodiment of the present application, a browser image loading device is provided, comprising:
[0027] An identification module, adapted to identify a target image format supported by the browser through a preset programming language; wherein the target image format refers to an image format with the smallest image file size among multiple image formats supported by the browser while maintaining a preset image quality;
[0028] Add module, suitable for adding target classes corresponding to target image formats to subject labels;
[0029] The loading module is suitable for loading image files of target image format according to the target class using the style selector.
[0030] According to another aspect of the embodiment of the present application, there is provided a computing device, including: a processor, a memory, a communication interface and a communication bus, wherein the processor, the memory and the communication interface communicate with each other via the communication bus;
[0031] The memory is used to store at least one executable instruction, and the executable instruction enables the processor to execute the operation corresponding to the above-mentioned browser image loading method.
[0032] According to another aspect of the embodiments of the present application, a computer storage medium is provided, in which at least one executable instruction is stored, and the executable instruction enables a processor to perform operations corresponding to the image loading method of the browser as described above.
[0033] According to another aspect of the embodiments of the present application, a computer program product is provided, comprising at least one executable instruction, wherein the executable instruction enables a processor to perform operations corresponding to the above-mentioned browser image loading method.
[0034] According to the browser image loading method, device, computing device and storage medium provided in the embodiments of the present application, a programming language supported by most browsers is used as a preset programming language, and the target image format supported by the browser is identified through the preset programming language. Compared with the prior art in which the browser sequentially requests image files of various formats during downgrade processing, it can effectively reduce traffic consumption and conveniently and effectively expand the applicability of the solution; by adding a target class corresponding to the target image format to the main tag, the image file of the target image format can be conveniently loaded according to the target class using a style selector, thereby efficiently realizing image downgrade processing, and completing image loading in the image format with the smallest image file size supported by the browser while ensuring image quality, effectively improving page performance, increasing page rendering speed, and improving user experience.
[0035] The above description is only an overview of the technical solution of the embodiment of the present application. In order to more clearly understand the technical means of the embodiment of the present application, it can be implemented in accordance with the contents of the specification. In order to make the above and other purposes, features and advantages of the embodiment of the present application more obvious and easy to understand, the specific implementation method of the embodiment of the present application is listed below. BRIEF DESCRIPTION OF THE DRAWINGS
[0036] Various other advantages and benefits will become apparent to those of ordinary skill in the art by reading the detailed description of the preferred embodiments below. The accompanying drawings are only used for the purpose of illustrating the preferred embodiments and are not to be considered as limiting the embodiments of the present application. Moreover, the same reference symbols are used throughout the accompanying drawings to represent the same components. In the accompanying drawings:
[0037] Figure 1 A schematic diagram showing a process flow of a method for loading images in a browser according to an embodiment of the present application is shown;
[0038] Figure 2 A schematic diagram showing a flow chart of a method for loading images in a browser according to another embodiment of the present application is shown;
[0039] Figure 3 A structural block diagram of a browser image loading device according to an embodiment of the present application is shown;
[0040] Figure 4 A schematic diagram of the structure of a computing device according to an embodiment of the present application is shown. DETAILED DESCRIPTION
[0041] The exemplary embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. Although the exemplary embodiments of the present disclosure are shown in the accompanying drawings, it should be understood that the present disclosure can be implemented in various forms and should not be limited by the embodiments set forth herein. On the contrary, these embodiments are provided to enable a more thorough understanding of the present disclosure and to fully convey the scope of the present disclosure to those skilled in the art.
[0042] First, the terms involved in one or more embodiments of the present application are explained.
[0043] avif format: is an efficient image format based on the AV1 video codec. The avif format is designed to provide higher compression efficiency and image quality than traditional image formats such as jpeg, png, and webp, and can obtain better picture details. avif utilizes the advanced compression technology of the AV1 video codec, which can significantly reduce the file size while maintaining or improving image quality.
[0044] Webp format: is an image format suitable for Web use launched by Google. Webp aims to provide efficient data compression and image quality to reduce file size and speed up web page loading. Webp supports two main image types: lossy compression and lossless compression.
[0045] JavaScript (JS): is a lightweight, interpreted or just-in-time compiled programming language with function-first approach. It is famous as a scripting language for developing web pages, but it is also used in many non-browser environments.
[0046] createImageBitmap method: exists in windows and workers, and is used to create a new ImageBitmap object. This method can accept a variety of different image sources and return a promise to resolve the ImageBitmap.
[0047] Base64 encoding: is a commonly used data encoding method, mainly used to convert binary data into text strings, so that these data can be safely transmitted in environments that do not support binary transmission. Base64 encoding is usually used for the transmission of email attachments, image data, certificate data, etc.
[0048] fetch method: used to initiate a request to obtain resources, it returns a promise that will be fulfilled after the request responds.
[0049] The blob method is used to convert the response body into a Blob object (Binary Large Object). It uses a response stream, reads it, and returns a promise that is resolved using the Blob. The Blob object represents the data content of a binary file and is usually used to read and write files. For example, the content of an image file can be read and written using the Blob object.
[0050] Figure 1 A schematic diagram of a process flow of a method for loading an image in a browser according to an embodiment of the present application is shown. Figure 1 As shown, the method comprises the following steps:
[0051] Step S101, identifying the target image format supported by the browser through a preset programming language.
[0052] Among them, commonly used image formats may include avif format, webp format, jpeg format, png format, etc. Under the condition of maintaining the same image quality, the image file size of avif format is smaller than the image file size of webp format, and the image file size of webp format is smaller than the image file size of jpeg format and png format. Specifically, under the condition of maintaining the same image quality, the image file size of avif format is about 35% of the image file size of jpeg format, and the image file size of webp format is about 75% of the image file size of jpeg format. Then the formulated image degradation scheme may be: give priority to avif format, secondly webp format, and thirdly jpeg format or png format. The image degradation scheme may be expressed as avif→webp→jpeg / png. If the picture tag commonly used in the prior art is used to implement the image degradation solution, when the browser does not support the avif format and the webp format, the browser will still request the image files in the avif format and the webp format in sequence during the downgrade process, and then request the image files in the jpeg format or the png format, which will generate a certain amount of traffic overhead. The traffic overhead generated by requesting the image files in the avif format and the webp format here is unnecessary traffic consumption.
[0053] In an embodiment of the present application, a programming language that can be supported by most browsers is used as a preset programming language. The image degradation scheme is implemented by the preset programming language, which can conveniently and effectively expand the applicability of the scheme. Specifically, the preset programming language can be JavaScript language. The target image format supported by the browser is identified by the preset programming language, wherein the target image format refers to the image format with the smallest image file size among multiple image formats supported by the browser while maintaining the preset image quality. Moreover, compared with requesting image files of each format in turn during the browser degradation process in the prior art, identifying the target image format supported by the browser by the preset programming language can effectively reduce traffic consumption.
[0054] Specifically, the picture degradation scheme can be divided into multiple levels of degradation, and the picture formats are divided into multiple categories according to the picture file size. Take the classification into three categories as an example, which are respectively called the first picture format, the second picture format and the third picture format. Among them, while maintaining the preset picture quality, the picture file size of the first picture format is smaller than the picture file size of the second picture format, and the picture file size of the second picture format is smaller than the picture file size of the third picture format. In step S101, it is possible to first determine whether the browser supports the first picture format through a preset programming language; if the first picture format is supported, the first picture format is used as the target picture format; if the first picture format is not supported, it is determined whether the browser supports the second picture format through a preset programming language; if the second picture format is supported, the second picture format is used as the target picture format; if the second picture format is not supported, the third picture format is used as the target picture format.
[0055] Among them, the first image format may be avif format, the second image format may be webp format, and the third image format may include jpeg format or png format. If the current browser supports avif format through the preset programming language recognition, the avif format can be determined as the target image format supported by the browser; if the current browser does not support avif format but supports webp format through the preset programming language recognition, the webp format can be determined as the target image format supported by the browser; if the current browser does not support avif format and webp format through the preset programming language recognition, the jpeg format or png format can be determined as the target image format supported by the browser.
[0056] Step S102, adding a target class corresponding to the target image format to the subject tag.
[0057] The body tag represents the main part of the HTML web page, that is, the content area actually displayed in the web page, that is, the content that users can see, which can include text, pictures, audio, video and other content. After identifying the target image format, the target class corresponding to the target image format can be added to the body tag. In object-oriented programming, a class is a construct in an object-oriented computer programming language that is used to define the blueprint of an object, that is, to define the properties and methods that an object should have.
[0058] Step S103, using the style selector to load the image file of the target image format according to the target class.
[0059] The style selector may be a CSS (Cascading Style Sheets) selector, which is a rule for selecting HTML elements and applying styles, and determines which elements will be styled and how they will be styled. By using the CSS selector according to the target class, it is possible to conveniently load image files of the target image format.
[0060] According to the browser image loading method provided in the embodiment of the present application, a programming language that can be supported by most browsers is used as a preset programming language, and the target image format supported by the browser is identified through the preset programming language. Compared with the prior art in which the browser sequentially requests image files of various formats during downgrade processing, this method can effectively reduce traffic consumption and conveniently and effectively expand the applicability of the solution; by adding a target class corresponding to the target image format to the main tag, and using a style selector according to the target class, the image file of the target image format can be conveniently loaded, thereby efficiently realizing image downgrade processing, and completing image loading in the image format with the smallest image file size supported by the browser while ensuring image quality, effectively improving page performance, increasing page rendering speed, and improving user experience.
[0061] Figure 2 A schematic diagram of a process flow of a method for loading an image in a browser according to another embodiment of the present application is shown. Figure 2 As shown, the method comprises the following steps:
[0062] Step S201, determine whether there is a method for creating a picture bitmap through a preset programming language; if so, execute step S202; if not, execute step S205.
[0063] The picture degradation scheme can be divided into multiple levels of degradation. For example, according to the picture file size, the picture format is divided into three categories, namely the first picture format, the second picture format and the third picture format. Among them, the first picture format is the avif format, the second picture format is the webp format, and the third picture format includes the jpeg format or the png format. Then the picture degradation scheme can be expressed as avif→webp→jpeg / png.
[0064] It is preferred to determine whether the browser supports the first image format through a preset programming language. The preset programming language may specifically be JavaScript. In step S201, it may be determined through JavaScript whether there is a method for creating an image bitmap (createImageBitmap). ImageBitmap is a technology for processing images on the Web and a high-performance image representation form. It can avoid delays in image decoding and improve the performance of drawing images in a canvas. Through the createImageBitmap method, an ImageBitmap instance can be created from an html element, a Blob, etc., asynchronously processed, and memory consumption reduced.
[0065] If there is a method for creating a picture bitmap, execute step S202; if there is no method for creating a picture bitmap, it means that the current browser does not support the first picture format, and execute step S205.
[0066] Step S202, request to obtain the image file of the first image format of the preset encoding method, when the request is successful, read the binary large object from the response, use the create image bitmap method to process the binary large object, and obtain the corresponding commitment object.
[0067] Taking the preset encoding method as base64 encoding as an example, you can use the fetch method to request a base64-encoded image / avif type image file. When the fetch request is successful, you can use the blob method to read a Blob object from the response and return a promise for the blob graphic data. Use the createImageBitmap method to process the Blob object and return a promise object (promise) to resolve the ImageBitmap.
[0068] Step S203, determine whether the asynchronous operation of the promised object is successful; if so, execute step S204; if not, execute step S205.
[0069] The states of the promised object include pending state (i.e., pending), successful state (i.e., fulfilled or resolved), and failed state (i.e., rejected), wherein the pending state is used to indicate the initial state, which is neither completed nor failed; the successful state is used to indicate that the asynchronous operation is successfully completed; and the failed state is used to indicate that the asynchronous operation fails. If the state of the promised object is a successful state, indicating that the asynchronous operation is successful, then step S204 is executed; if the state of the promised object is a failed state, indicating that the asynchronous operation fails, then step S205 is executed.
[0070] Step S204: determine whether the first picture format is supported, and use the first picture format as the target picture format.
[0071] When the asynchronous operation of the promised object succeeds, it is determined that the first picture format is supported, and the first picture format is used as the target picture format, that is, the avif format is used as the target picture format.
[0072] Step S205: determine that the first picture format is not supported.
[0073] When there is no method for creating an image bitmap and when the asynchronous operation of the promised object fails, it is determined that the first image format is not supported. Then it is necessary to determine whether the browser supports the second image format through a preset programming language, which can be specifically achieved through steps S206 to S209.
[0074] Step S206: Create a canvas tag using a preset programming language, and convert the content of the canvas tag into a string.
[0075] Specifically, when creating a canvas tag using JavaScript, you can use the toDataURL method to convert the content in the canvas tag into a string. The toDataURL method is a method provided for the canvas tag in HTML, which is used to convert the content in the canvas tag into a string containing image data. This string can be a data URL.
[0076] Step S207, detecting whether the character string contains a preset field corresponding to the second image format; if so, executing step S208; if not, executing step S209.
[0077] The preset field corresponding to the second image format may specifically be an image / webp field. For example, the indexOf method may be used to detect whether the string contains the image / webp field. The indexOf method may be used to return the index of the first occurrence of a given element in an array, and -1 if it does not exist. If the string contains the preset field, step S208 is executed; if the string does not contain the preset field, step S209 is executed.
[0078] Step S208: determine whether the second picture format is supported, and use the second picture format as the target picture format.
[0079] When the preset field is included in the character string, it is determined that the second picture format is supported, and the second picture format is used as the target picture format, that is, the webp format is used as the target picture format.
[0080] Step S209: determine that the second picture format is not supported, and use the third picture format as the target picture format.
[0081] When the string does not contain the preset field, it is determined that the second image format is not supported, and the third image format is used as the target image format, that is, the jpeg format or the png format is used as the target image format. In actual applications, the ternary operator in the JavaScript language can be used to determine whether the current browser supports neither the first image format nor the second image format. If so, the third image format is used as the target image format.
[0082] Step S210, adding a target class corresponding to the target image format to the subject tag.
[0083] Add a target class corresponding to the target image format to the body tag. For example, when the target image format is avif, add avif class to the body tag; when the target image format is webp, add webpclass to the body tag; when the target image format is jpeg or png, add jpg-png class to the body tag. The target class can contain script tags and other content. The script tag is a tag in HTML used to define client scripts (usually JavaScript). It allows JavaScript code to be embedded directly in HTML documents or external JavaScript files to be referenced.
[0084] Step S211, using the style selector to load the image file of the target image format according to the target class.
[0085] When the target image format is avif, the CSS selector can be used to load the image file in avif format according to avif class; when the target image format is webp, the CSS selector can be used to load the image file in webp format according to webp class; when the target image format is jpeg or png, the CSS selector can be used to load the image file in jpeg or png according to jpg-pngclass. Taking the image file as a game image as an example, under the condition of equal image quality, the size of the image file in avif format to be loaded is 30.6KB, the size of the image file in webp format is 53.7KB, and the size of the image file in png format is 302KB. The solution provided by this embodiment effectively realizes the image degradation processing, so that the browser can complete the image loading in the image format with the smallest image file size supported by it.
[0086] According to the browser image loading method provided by the embodiment of the present application, by judging whether there is a method for creating an image bitmap and the execution of the asynchronous operation of the commitment object obtained by processing the binary large object using the method for creating an image bitmap, it is possible to accurately judge whether the browser supports the first image format; by detecting whether the string converted by the canvas tag contains a preset field corresponding to the second image format, it is possible to quickly judge whether the browser supports the second image format, and when the browser neither supports the first image format nor the second image format, the third image format can be used as the target image format; the scheme uses JavaScript language to identify the target image format supported by the browser, which can effectively reduce traffic consumption compared with the prior art in which the browser sequentially requests image files of various formats during the downgrade process, and JavaScript language can be well applied to various browsers. By using JavaScript language to implement the image downgrade scheme, the applicability of the scheme can be conveniently and effectively expanded; by adding a target class corresponding to the target image format to the main tag, the image file of the target image format can be conveniently loaded according to the target class using a style selector, thereby efficiently realizing the image downgrade process, and completing the image loading in the image format with the smallest image file size supported by the browser while ensuring the image quality, effectively improving the page performance.
[0087] Figure 3 A structural block diagram of a browser image loading device according to an embodiment of the present application is shown. Figure 3 As shown, the device includes: an identification module 310 , an adding module 320 and a loading module 330 .
[0088] The identification module 310 is adapted to: identify a target image format supported by the browser through a preset programming language; wherein the target image format refers to an image format with the smallest image file size among multiple image formats supported by the browser while maintaining a preset image quality.
[0089] The adding module 320 is adapted to add a target class corresponding to a target image format to the subject tag.
[0090] The loading module 330 is adapted to load a picture file of a target picture format according to a target class using a style selector.
[0091] Optionally, the identification module 310 is further adapted to: determine whether the browser supports a first image format through a preset programming language; if the first image format is supported, use the first image format as the target image format; if the first image format is not supported, determine whether the browser supports a second image format through a preset programming language; if the second image format is supported, use the second image format as the target image format; if the second image format is not supported, use the third image format as the target image format; wherein, while maintaining a preset image quality, the image file size of the first image format is smaller than the image file size of the second image format, and the image file size of the second image format is smaller than the image file size of the third image format.
[0092] Optionally, the first image format is avif format; the identification module 310 is further suitable for: determining whether there is a method for creating an image bitmap through a preset programming language; if there is a method for creating an image bitmap, requesting to obtain an image file of the first image format in a preset encoding method, and when the request is successful, reading a binary large object from the response, using the method for creating an image bitmap to process the binary large object, and obtaining a corresponding commitment object; if the asynchronous operation of the commitment object succeeds, determining that the first image format is supported; if there is no method for creating an image bitmap or the asynchronous operation of the commitment object fails, determining that the first image format is not supported.
[0093] Optionally, the second image format is a webp format; the identification module 310 is further adapted to: create a canvas tag through a preset programming language, convert the content of the canvas tag into a string, and detect whether the string contains a preset field corresponding to the second image format; if the preset field is contained, it is determined that the second image format is supported; if the preset field is not contained, it is determined that the second image format is not supported.
[0094] Optionally, the third image format includes: jpeg format or png format.
[0095] Optionally, the preset programming language is JavaScript.
[0096] The description of each module above refers to the corresponding description in the method embodiment and will not be repeated here.
[0097] According to the browser image loading device provided by the embodiment of the present application, by judging whether there is a method for creating an image bitmap and the execution of the asynchronous operation of the commitment object obtained by processing the binary large object using the method for creating an image bitmap, it is possible to accurately judge whether the browser supports the first image format; by detecting whether the string converted by the canvas tag contains a preset field corresponding to the second image format, it is possible to quickly judge whether the browser supports the second image format, and when the browser neither supports the first image format nor the second image format, the third image format can be used as the target image format; the scheme uses JavaScript language to identify the target image format supported by the browser, which can effectively reduce traffic consumption compared with the prior art in which the browser sequentially requests image files of various formats during the downgrade process, and JavaScript language can be well applied to various browsers. By using JavaScript language to implement the image downgrade scheme, the applicability of the scheme can be conveniently and effectively expanded; by adding a target class corresponding to the target image format to the main tag, the image file of the target image format can be conveniently loaded according to the target class using a style selector, thereby efficiently realizing the image downgrade process, and completing the image loading in the image format with the smallest image file size supported by the browser while ensuring the image quality, effectively improving the page performance.
[0098] An embodiment of the present application provides a non-volatile computer storage medium, which stores at least one executable instruction or computer program, which can enable a processor to perform operations corresponding to the browser image loading method in any of the above method embodiments.
[0099] An embodiment of the present application provides a computer program product, which includes at least one executable instruction or computer program, and the executable instruction or computer program can enable a processor to perform operations corresponding to the browser image loading method in any of the above method embodiments.
[0100] Figure 4 A schematic diagram of the structure of a computing device according to an embodiment of the present application is shown. The specific embodiment of the present application does not limit the specific implementation of the computing device.
[0101] like Figure 4 As shown, the computing device may include: a processor (processor) 402 , a communications interface (Communications Interface) 404 , a memory (memory) 406 , and a communication bus 408 .
[0102] The processor 402, the communication interface 404, and the memory 406 communicate with each other via the communication bus 408. The communication interface 404 is used to communicate with other devices such as a client or other server network elements. The processor 402 is used to execute the program 410, which can specifically execute the relevant steps in the above-mentioned embodiment of the method for loading an image in a browser of a computing device.
[0103] Specifically, the program 410 may include program codes, which include computer operation instructions.
[0104] The processor 402 may be a central processing unit (CPU), or an application-specific integrated circuit (ASIC), or one or more integrated circuits configured to implement the embodiments of the present application. The one or more processors included in the computing device may be processors of the same type, such as one or more CPUs; or processors of different types, such as one or more CPUs and one or more ASICs.
[0105] The memory 406 is used to store the program 410. The memory 406 may include a high-speed RAM memory, and may also include a non-volatile memory (non-volatile memory), such as at least one disk memory.
[0106] The program 410 can be specifically used to enable the processor 402 to execute the browser image loading method in any of the above-mentioned method embodiments. The specific implementation of each step in the program 410 can refer to the corresponding descriptions in the corresponding steps and units in the above-mentioned browser image loading embodiment, which will not be repeated here. Those skilled in the art can clearly understand that for the convenience and simplicity of description, the specific working process of the above-described devices and modules can refer to the corresponding process description in the above-mentioned method embodiment, which will not be repeated here.
[0107] The algorithm and display provided herein are not inherently related to any specific computer, virtual system or other equipment. Various general purpose systems can also be used together with the teachings based on this. According to the above description, it is obvious to construct the structure required for this type of system. In addition, the present application embodiment is not directed to any specific programming language yet. It should be understood that various programming languages can be utilized to realize the content of the present application embodiment described herein, and the above description of specific languages is to disclose the best mode of implementation of the present application embodiment.
[0108] In the description provided herein, a large number of specific details are described. However, it is understood that the embodiments of the present application can be practiced without these specific details. In some instances, well-known methods, structures and techniques are not shown in detail so as not to obscure the understanding of this description.
[0109] Similarly, it should be understood that in order to streamline the present disclosure and help understand one or more of the various inventive aspects, in the above description of the exemplary embodiments of the present application, the various features of the embodiments of the present application are sometimes grouped together into a single embodiment, figure, or description thereof. However, the disclosed method should not be interpreted as reflecting the following intention: the claimed embodiments of the present application require more features than the features clearly stated in each claim. More specifically, as reflected in the claims below, the inventive aspects are less than all the features of the single embodiment disclosed above. Therefore, the claims following the specific embodiment are hereby explicitly incorporated into the specific embodiment, wherein each claim itself serves as a separate embodiment of the embodiment of the present application.
[0110] Those skilled in the art will appreciate that the modules in the devices in the embodiments may be adaptively changed and arranged in one or more devices different from the embodiments. The modules or units or components in the embodiments may be combined into one module or unit or component, and in addition they may be divided into a plurality of submodules or subunits or subcomponents. Except that at least some of such features and / or processes or units are mutually exclusive, all features disclosed in this specification (including the accompanying claims, abstracts and drawings) and all processes or units of any method or device disclosed in this manner may be combined in any combination. Unless otherwise expressly stated, each feature disclosed in this specification (including the accompanying claims, abstracts and drawings) may be replaced by an alternative feature providing the same, equivalent or similar purpose.
[0111] In addition, those skilled in the art will appreciate that, although some embodiments described herein include certain features included in other embodiments but not other features, the combination of features of different embodiments is meant to be within the scope of the embodiments of the present application and to form different embodiments. For example, in the claims below, any one of the claimed embodiments may be used in any combination.
[0112] The various component embodiments of the embodiments of the present application can be implemented in hardware, or in software modules running on one or more processors, or in a combination thereof. It should be understood by those skilled in the art that a microprocessor or digital signal processor (DSP) can be used in practice to implement some or all functions of some or all components according to the embodiments of the present application. The embodiments of the present application can also be implemented as a device or apparatus program (e.g., computer program and computer program product) for executing part or all of the methods described herein. Such a program implementing the embodiments of the present application can be stored on a computer-readable medium, or can have the form of one or more signals. Such a signal can be downloaded from an Internet website, or provided on a carrier signal, or provided in any other form.
[0113] It should be noted that the above embodiments illustrate rather than limit the embodiments of the present application, and that those skilled in the art may design alternative embodiments without departing from the scope of the appended claims. In the claims, any reference symbol between brackets should not be constructed as a limitation to the claims. The word "comprising" does not exclude the presence of elements or steps not listed in the claims. The word "one" or "an" preceding an element does not exclude the presence of multiple such elements. The embodiments of the present application may be implemented by means of hardware including several different elements and by means of appropriately programmed computers. In a unit claim that lists several devices, several of these devices may be embodied by the same hardware item. The use of the words first, second, and third, etc. does not indicate any order. These words may be interpreted as names.
Claims
1. A method for loading an image in a browser, comprising: Identifying a target image format supported by the browser through a preset programming language; wherein the target image format refers to an image format with the smallest image file size among multiple image formats supported by the browser while maintaining a preset image quality; Adding a target class corresponding to the target image format to the subject label; The image file of the target image format is loaded according to the target class using a style selector.
2. According to the method of claim 1, the step of identifying the target image format supported by the browser by using a preset programming language further comprises: Determining whether the browser supports a first image format by using the preset programming language; If the first picture format is supported, using the first picture format as the target picture format; If the first picture format is not supported, determining whether the browser supports the second picture format by using the preset programming language; If the second picture format is supported, using the second picture format as the target picture format; If the second picture format is not supported, using the third picture format as the target picture format; Wherein, while maintaining a preset image quality, the image file size of the first image format is smaller than the image file size of the second image format, and the image file size of the second image format is smaller than the image file size of the third image format.
3. The method according to claim 2, wherein the first image format is an avif format; The determining whether the browser supports the first image format by using the preset programming language further includes: Determine whether there is a method for creating a picture bitmap by using the preset programming language; If the method for creating a picture bitmap exists, request to obtain a picture file of the first picture format in a preset encoding method, and when the request is successful, read a binary large object from the response, use the method for creating a picture bitmap to process the binary large object, and obtain a corresponding commitment object; if the asynchronous operation of the commitment object is successful, it is determined that the first picture format is supported; If the method for creating a picture bitmap does not exist or the asynchronous operation of the promise object fails, it is determined that the first picture format is not supported.
4. The method according to claim 2, wherein the second image format is a webp format; The determining whether the browser supports the second image format by the preset programming language further includes: Creating a canvas tag by using the preset programming language, converting the content of the canvas tag into a string, and detecting whether the string contains a preset field corresponding to the second image format; If the preset field is included, it is determined that the second picture format is supported; If the preset field is not included, it is determined that the second picture format is not supported.
5. The method according to any one of claims 2 to 4, wherein the third picture format comprises: jpeg or png format.
6. According to the method according to any one of claims 1 to 5, the preset programming language is JavaScript language.
7. A browser image loading device, comprising: An identification module, adapted to identify a target image format supported by the browser through a preset programming language; wherein the target image format refers to an image format with the smallest image file size among multiple image formats supported by the browser while maintaining a preset image quality; An adding module, adapted to add a target class corresponding to the target image format to the subject tag; The loading module is adapted to load the image file of the target image format according to the target class using a style selector.
8. A computing device comprising: A processor, a memory, a communication interface and a communication bus, wherein the processor, the memory and the communication interface communicate with each other via the communication bus; The memory is used to store at least one executable instruction, and the executable instruction enables the processor to perform an operation corresponding to the browser image loading method according to any one of claims 1-6.
9. A computer storage medium, wherein at least one executable instruction is stored in the storage medium, and the executable instruction enables a processor to execute an operation corresponding to the browser image loading method according to any one of claims 1 to 6.
10. A computer program product, comprising at least one executable instruction, wherein the executable instruction enables a processor to execute operations corresponding to the browser image loading method according to any one of claims 1 to 6.
Citation Information
Patent Citations
Picture processing method and device
CN109684568A
Page loading method and device and electronic equipment
CN112800372A
Webpage picture resource processing method and device
CN114036419A
Webp graph compatible rendering loading method and device, equipment and medium
CN115495685A
Distribution system, distribution method and program
JP2023159966A
