Make a WordPress website performance optimization example based on a website

» network technique » Make a WordPress website performance optimization example based on a website

Now it is popular to say that Baidu Google has begun to abandon websites with slow opening speed. However, there are many factors affecting the website speed, but the performance of a website is absolute. Generally speaking, a website with fast opening speed may not have good performance, but a website with good performance will not be any worse, Today, I use a website of my friend chain to analyze the problems of website performance optimization.

根据某网站来做一个WordPress网站性能优化实例-极客公园

preface

根据某网站来做一个WordPress网站性能优化实例-极客公园

rule

根据某网站来做一个WordPress网站性能优化实例-极客公园

As shown in the figure above, the website performance is classified into A/B/C/D/E/F according to the order. A is the best, while the latter is the reverse. Because it is a test server from Canada, we do not look at the loading time, which has no reference value. We mainly look at the pagespeed and yslow tags. The following recommendation items, scores, categories, priorities, Now let's analyze the problems of this website.

PageSpeed analysis

Let's take a look at the specific analysis report of PageSpeed, as shown below
根据某网站来做一个WordPress网站性能优化实例-极客公园

Let's begin to analyze and solve each of them.

Enable gzip compression

This means that Gzip compression needs to be enabled to reduce the size of files sent from the server to increase the speed of transmission to the browser.

根据某网站来做一个WordPress网站性能优化实例-极客公园

How to check your website for gzip compression? You can try the following website:
Station master directly Gzip detection
On how to open Gzip, 115 met a very comprehensive article

http://www.511yj.com/wordpress-seo-gzip.html

In addition, Cloud Cloud can add the following code in the wp-config.php file

 define( 'ENFORCE_GZIP', true );

Leverage browser caching

This is to enable browser caching. We all know that caching is generally divided into server-side caching and client-side caching [that is, browser caching]. Once users open our website, they will download several static resources from our server. We should let the files downloaded to the client's browser cache continue to be used, There is no need to repeatedly download files from the server.

根据某网站来做一个WordPress网站性能优化实例-极客公园

The solution is also very simple. Just add the following code in the server htaccess file [Cloud Cloud for its own use]

 ##File Cache## <FilesMatch ".(html|gif|jpg|jpeg|png|ico|js|css)$"> Header set Cache-Control "max-age=2592000" </FilesMatch>

In fact, this project is very similar to one of Yahoo's projects. Let's talk about it as follows.

Optimize images

This project is very simple. It is just to optimize pictures. Generally, it is jpg and png pictures. If you can't optimize them, you can directly click the image on the right optimized version , you can download the compressed version directly.

根据某网站来做一个WordPress网站性能优化实例-极客公园

As for image compression, there are many solutions:

Antelope: Recommended download of excellent image compression tools

Antelope is a very good, simple image compression software. It supports the compression of jpg and png images. The interface is very small and fresh, and it is relatively [...]

Baidu online disk

Specify image dimensions

Assigning a size to an image simply saves the browser's trouble. That is, if you assign a size to an image, the browser will directly display the image as you specify. If you do not specify a size, the browser will go back to check the size of the image itself, and then display the image according to the actual situation. This virtually increases the burden on the browser, After all, the main task of the browser is to render the entire page.

Let's take a chestnut:

 <img src="xxoo/xxoo.jpg">

This code is a high-speed browser. There is a breakthrough here. The address is xxooxxoo. As for the size is not marked, the browser needs to check the image itself

 <img width="250px" height="250px"  src="xxoo/xxoo.jpg">

The following sentence tells the browser that there is a picture here, the address is xxooxxoo, and the size is 250 * 250. Then the browser will display it directly according to the size you specified. This will help the browser to reduce the burden virtually. The version browser reduces the burden, which is to speed up the display of web pages!

Minify JavaScript

Compressing the js file is easy to understand. When many js tutorials teach you how to use it, they often give you the uncompressed version, mainly to facilitate secondary development. But when you are finished developing and put into use, please pay attention to compressing it. Square and normal compression will not affect the use, such as jQuery.

根据某网站来做一个WordPress网站性能优化实例-极客公园

Here is a recommended js compression tool. Of course, after you compress a file, you should check whether related functions are affected.
Js online compression

Specify a cache validator

Set a cache verification. Some plug-ins or themes will use. css.php or js.php to dynamically load static files, which causes the browser to fail to correctly obtain cache verification
根据某网站来做一个WordPress网站性能优化实例-极客公园

 <IfModule mod_headers.c> <FilesMatch ".(php)$"> Header set Last-Modified "Tue, 31 Aug 2018 00:00:00 GMT" </FilesMatch> </IfModule>

Minify CSS

Compressing CSS is the same as compressing js above. Compress useless code, reduce file size, and speed up loading

根据某网站来做一个WordPress网站性能优化实例-极客公园

Online compression CSS tool

Remove query strings from static resources

Remove the query character of the static file. In short, the link of the static file cannot contain ""? Question mark. We will take a two-step look at this site.
根据某网站来做一个WordPress网站性能优化实例-极客公园

Step 1: contact the question mark in the thumbnail. Because the timthumb scheme used by the website thumbnail can adopt cloud storage solutions such as Qiniu, Youpai, OSS, etc., which can be solved by image processing+custom image style names.
Step 2: For query characters other than thumbnails, we can use the following method:

WordPress optimization: disable website static resource version query

Optimize WordPress by disabling version query of WordPress static resources. Remove Query stri [...]

Specify a Vary: Accept-Encoding header

It's still a head problem. It's mainly about whether I can compress it. It's not a big problem. It's OK not to set it
根据某网站来做一个WordPress网站性能优化实例-极客公园

 <IfModule mod_headers.c> <FilesMatch ".(js|css|xml|gz|html)$"> Header append Vary: Accept-Encoding </FilesMatch> </IfModule>

Enable Keep-Alive

Enabling HTTP Keep Alive or HTTP persistent connection allows the same TCP connection to send and receive multiple HTTP requests, thus reducing the delay of subsequent requests. For example, do you close the door from the bedroom version to the living room without opening it once, or do you close it after moving things? Actually, it's easy to understand
The solution is also simple. It is still an htaccess file

 <ifModule mod_headers.c> Header set Connection keep-alive </ifModule>

Defer parsing of JavaScript

Delay loading the js file, which simply means putting the js file at the end of execution, and putting it in WordPress means loading the js file in this way

 wp_register_script('default', get_template_directory_uri() . '/ assets/js/global.js', false, '1.0', true );// Bottom loading wp_enqueue_script('default');

Yslow analysis

Yahoo's Yslow analysis results are also very poor, but the problems are relatively concentrated
根据某网站来做一个WordPress网站性能优化实例-极客公园

Add Expires headers

Adding an expired header to a static file is the same as the browser cache previously mentioned. You can also use the above code directly
根据某网站来做一个WordPress网站性能优化实例-极客公园

Yunluo can also provide a more complete copy here, which is almost the same

 <IfModule mod_expires.c> # Enable expirations ExpiresActive On  # Default directive ExpiresDefault "access plus 1 month" # My favicon ExpiresByType image/x-icon "access plus 1 year" # Images ExpiresByType image/gif "access plus 1 month" ExpiresByType image/png "access plus 1 month" ExpiresByType image/jpg "access plus 1 month" ExpiresByType image/jpeg "access plus 1 month" # CSS ExpiresByType text/css "access plus 1 month" # Javascript ExpiresByType application/javascript "access plus 1 year" </IfModule>

Make fewer HTTP requests

Reduce http requests, simply put some unnecessary static files that exist separately and often run together
根据某网站来做一个WordPress网站性能优化实例-极客公园

There are 20 js requests and 9 css requests. Don't forget, there are also several image requests......

Use a Content Delivery Network (CDN)

This is to let you use CDN. In fact, there is a lot of talk about CDN, but people often ask me: Why is it not fast when using XXX, but slow? Is it true to use XXX acceleration? Why didn't you feel it? In short, various problems.
根据某网站来做一个WordPress网站性能优化实例-极客公园

As for CDN, I would like to make a simple analogy. Usually I go to the supermarket at the entrance of the community to get soy sauce, and I have to run more than half of the community if I have nothing to do. One day, we opened a small shop downstairs. Now I go directly to the shop downstairs to get soy sauce. Do you think it's faster to go to the supermarket at the entrance or go downstairs to get soy sauce? The reason is obvious.

Use cookie-free domains

To put it simply, some domain names without cookies are used to transfer static files. In fact, it is still a CDN problem, which is solved when CDN is solved.

Reduce the number of DOM elements

There is no good way to reduce the number of DOM elements. You can only start from the WordPress theme, which requires you to have some skills.

Load on demand

Loading on demand is an idea behind the cloud, not a specific method. To put it simply, what is not needed on the current page should be banned from loading. Here's a simple example:
First: Picture pop-up window
Generally, the image pop-up window will be applied to the article page, and the home page rarely uses this function, so the js and css for the image pop-up window should be arranged to load on the article page, which is simply to do is_single() It's just a judgment.
Second: code highlighting
As above, generally speaking, code highlighting is also used in the article page, but many code highlighting plug-ins also load relevant js and css files on the home page for compatibility, so they should also be moved to the article page.
Third: short code
Cloud Cloud likes to use short code, but using short code will also add some code, and not every article will use a short code. If relevant resources are loaded directly, is it a waste? We can load resources by judging whether short code exists. give an example:

 function secret_css() { global $post; if ( has_shortcode( $post->post_content, 'secret') || has_shortcode( $post->post_content, 'vip')  ){ echo '<style type="text/css">.wxpic{float:left;width:18%}.wxtips{color:#32B9B5;float:left;width:72%;padding-left:5%;padding-top:0;font-size:20px;line-height:150%;text-align:left;font-family:Microsoft YaHei}.yzts{margin-left: 40px}@media (max-width:600px){.yzts{margin-left:5px}.wxpic{float:left}.wxbox #verifycode{width:35%} .wxbox #verifybtn{width:22%}.wxpic,.wxtips{width:100%}.wxtips{font-size:15px;padding:2px}}</style>';}} add_action('wp_head', 'secret_css');

Fourth: background resources
Many articles have said that the WordPress background is also very jammed. I can check in detail how many resources are loaded in the background. We can generally load some necessary resources according to the current page.

Postscript

After all that talk, someone must ask, how is your blogger? Let me take a picture
根据某网站来做一个WordPress网站性能优化实例-极客公园

Of course, if you are a trench player, you can ignore the article and pay more to improve the broadband. Good CDN can solve this problem.

Related Links

Gtmetrix Cloud detection report Report of sample website

--End--

Post reply

Your email address will not be disclosed. Required items have been used * tagging

11 Replies to "Create a WordPress website performance optimization instance based on a website"

  1. Where are the expired header codes added... Forgive Xiaobai. I checked two B's. One asked me to add the expired header, and the other asked me to add the CDN and browser cache. The browser cache is set according to your method, and it is close to the expiration header. Thank you.

    1. @ Learning Notes of Mingyue Climbing the Tower Limited, because this is judged according to the content of the response. Not based on speed. In addition, if CDN is used, some optimizations of the origin site will be invalid. For example, the website mentioned in the article has actually been optimized, but 360 website guards have been added, and the response to the browser is 360, not the origin site