This article will share with you a practical application of a small program to see how to optimize images in the small program. I hope it will be helpful to everyone!
Front-end performance optimization and image optimization are indispensable and important links. The rendering of images is indispensable for the composition of most website pages. Especially in e-commerce projects, there are often a large number of pictures, such as banner advertising pictures, menu navigation pictures, product list pictures, etc. Loading a large number of images and excessively large image sizes often affect the page loading speed, resulting in a poor user experience. [Related learning recommendations: 小program development tutorial]
Optimization plan
The main problem based on the above problems is the number of pictures and the size of the pictures, so How to improve image loading speed and improve user experience. In fact, there are many excellent solutions for image optimization, and we can all learn from them. Finally, we optimize the image as a whole in different directions.
Use appropriate image formats
Currently widely used WEB image formats include JPEG/JPG, PNG, GIF, WebP, Base64, SVG, etc., these formats have their own characteristics. The following is a brief summary:
Using appropriate image formats can usually lead to smaller image byte sizes , through a reasonable compression rate, the image size can be reduced without affecting the image quality.
Reduce network transmission
The applet uses Tencent Cloud Image Server, which provides many image processing functions, such as image scaling, image reduction Quality, format conversion, image cropping, image rounding and other functions. These functions can be achieved by adding specified parameters to the image URL. The image server will process the image in advance according to the parameter settings and save it to the CDN server, which greatly reduces image transmission. size.
Currently, the image URLs returned by the background interface are all without setting the image parameter preprocessing. For example, a 800x800 size high-definition product image has a volume of about 300k. , which can easily lead to slow image loading and rendering, high user traffic consumption, and seriously affects the user experience. Therefore, we combine the image processing function of Tencent Cloud. Before loading the network image, we first detect whether it is the image URL of the Tencent Cloud domain name. If the domain name matches, the image URLPerform preprocessing, which includes Add scaling parameters, Add degradation parameters,Add WebP parameters to reduce image network transmission size
Let's first look at a picture that passes through the picture server and uses Tencent Cloud's picture processing capabilities. By setting the picture scaling/degradation/WebP, a picture with a size of 800x800 and a volume of 246KB is finally output and generated. 25.6KB, the image size is reduced by 80%, the effect is remarkable.
Image scaling
Currently, the business background uploads original images, and the original image size may be larger than the actual size displayed on the client. Large size will lead to slow image loading on the one hand, and waste of user traffic on the other. If a large-sized image is loaded, it will also affect the rendering performance, making the user feel stuck and affecting the user experience. By adding a scaling parameter, specify the image server to deliver an image size that is smaller and more consistent with the actual display size.
Picture degradation
The picture server supports picture quality, the value range is 0-100, the default value is the original picture quality, by reducing the picture Quality can reduce the image size, but too much quality reduction will also affect the display effect of the image. The network default image quality reduction parameter is set to 85, which is also provided through the mini program: wx.getNetworkType, wx.onNetworkStatusChange, offNetworkStatusChange interfaces monitor network status changes to obtain the current user's network type networkType, such as the 4G# currently used by the user ## network, the image quality will be dynamically set to 80. For most business situations, on the one hand, it can greatly reduce the image download size and ensure user experience, on the other hand, it saves users browsing. Currently, adding images reduces the Quality parameters can reduce the image size by at least 30-40%.
As mentioned above, different image formats have their own advantages, disadvantages and usage scenarios. Among them, WebP image format provides lossy compression and Lossless compressed image format. According to official data from Google, compared with PNG, the number of bytes of WebPlossless images is 26%, WebPlossy images have 25-34% fewer bytes than similar JPGimages. Nowadays, the products of major Internet companies have been used, such as Taobao, JD.com, and Meituan.
automatically adds WebP# for the png/jpg image format. ## Parameters, converted to WebP image format. Although WebP may take longer to decode than png/jpg, the relative network transmission speed is still greatly improved. Currently, the ios 13 system version has a large proportion of users. The applet obtains the current system version and does not add WebP parameters for downgrade processing.
The above is the detailed content of Let's talk in depth about how to optimize images in mini programs. For more information, please follow other related articles on the PHP Chinese website!
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
With the popularity of mobile Internet technology and smartphones, WeChat has become an indispensable application in people's lives. WeChat mini programs allow people to directly use mini programs to solve some simple needs without downloading and installing applications. This article will introduce how to use Python to develop WeChat applet. 1. Preparation Before using Python to develop WeChat applet, you need to install the relevant Python library. It is recommended to use the two libraries wxpy and itchat here. wxpy is a WeChat machine
Mini programs can use react. How to use it: 1. Implement a renderer based on "react-reconciler" and generate a DSL; 2. Create a mini program component to parse and render DSL; 3. Install npm and execute the developer Build npm in the tool; 4. Introduce the package into your own page, and then use the API to complete the development.
Implementing card flipping effects in WeChat mini programs In WeChat mini programs, implementing card flipping effects is a common animation effect that can improve user experience and the attractiveness of interface interactions. The following will introduce in detail how to implement the special effect of card flipping in the WeChat applet and provide relevant code examples. First, you need to define two card elements in the page layout file of the mini program, one for displaying the front content and one for displaying the back content. The specific sample code is as follows: <!--index.wxml-->&l
According to news from this site on October 31, on May 27 this year, Ant Group announced the launch of the "Chinese Character Picking Project", and recently ushered in new progress: Alipay launched the "Chinese Character Picking-Uncommon Characters" mini program to collect collections from the society Rare characters supplement the rare character library and provide different input experiences for rare characters to help improve the rare character input method in Alipay. Currently, users can enter the "Uncommon Characters" applet by searching for keywords such as "Chinese character pick-up" and "rare characters". In the mini program, users can submit pictures of rare characters that have not been recognized and entered by the system. After confirmation, Alipay engineers will make additional entries into the font library. This website noticed that users can also experience the latest word-splitting input method in the mini program. This input method is designed for rare words with unclear pronunciation. User dismantling
How uniapp can achieve rapid conversion between mini programs and H5 requires specific code examples. In recent years, with the development of the mobile Internet and the popularity of smartphones, mini programs and H5 have become indispensable application forms. As a cross-platform development framework, uniapp can quickly realize the conversion between small programs and H5 based on a set of codes, greatly improving development efficiency. This article will introduce how uniapp can achieve rapid conversion between mini programs and H5, and give specific code examples. 1. Introduction to uniapp unia
Implementation idea: Establishing the server side of thread, so as to process the various functions of the chat room. The establishment of the x02 client is much simpler than the server. The function of the client is only to send and receive messages, and to enter specific characters according to specific rules. To achieve the use of different functions, therefore, on the client side, you only need to use two threads, one is dedicated to receiving messages, and the other is dedicated to sending messages. As for why not use one, that is because, only
Mini program registration operation steps: 1. Prepare copies of personal ID cards, corporate business licenses, legal person ID cards and other filing materials; 2. Log in to the mini program management background; 3. Enter the mini program settings page; 4. Select " "Basic Settings"; 5. Fill in the filing information; 6. Upload the filing materials; 7. Submit the filing application; 8. Wait for the review results. If the filing is not passed, make modifications based on the reasons and resubmit the filing application; 9. The follow-up operations for the filing are Can.
In Vue development, image scaling is a common requirement. When we display images on web pages, we may encounter image size mismatch problems. To solve this problem, we can take some optimization measures. First, we can use the object-fit property of CSS to control how the image is scaled. object-fit has several value options, such as fill, contain, cover, etc. By setting different values, we can achieve effects such as tiling and proportional scaling of images. example