Often times, ourWordPressOpen speed is very slow, is due to too many pictures in the web page, the server bandwidth itself is not enough to cause this situation, and then a check, the web page in the picture is too big, each picture is a few hundred K, or even 1-2M, open the web page to the site to load these pictures, greatly reducing the web page to open the speed, so at this time we choose to optimize the picture, reduce the size of the picture of the way to speed up the site.
Here we are going to introduce a new image format, the webp format.
WebP is a modern image format developed by GoogleIt is designed to provide smaller file sizes and higher image quality. It supports both lossy and lossless compression techniques while allowing transparency and animation. Compared to traditional JPEG and PNG formats, WebP can significantly reduce file size while maintaining image quality.
So the advantage of webp is that it doesn't compromise the quality of the image, but the image size is smaller.
Next, we'll explain how to convert all the images on your website to webp format.
1, first of all, we will be in the site directory of all the picture attachments into webp format, in the background to find Images to Webp plugin, and install it!
Plugin installed We then add the corresponding code in accordance with the instructions of the plugin, after the enable, otherwise the enable will report an error.
2, add the code needed for the plugin:
First code:
map $arg_no_webp $no_webp{
default "";
"1" "no_webp".
}
map $http_accept $webp_suffix{
default "";
"~*webp" ".webp"; }
}
After adding the first piece of code, restart Nginx.
Next, open the site's configuration and add another piece of code.
Second code:
location ~* ^/. +\. (png|gif|jpe?g)$ {
add_header Vary Accept.
try_files $uri$webp_suffix$no_webp $uri =404;
}
At this point, the plug-in required code, all added to complete, and then we return to the website background plug-in management, start Images to Webp plug-in.
Wait for the prompt to complete (if you site more pictures, please wait patiently, the conversion takes time, may be more than ten minutes, or 1-2 hours), so far, all the pictures of your site into webp format, the picture volume is smaller.
Here we open the site to test, the effect (open the page press F12, select Network, you can see):