We all hope that when someone accesses our WordPress website, we can quickly see the article, but there are no basic optimization skills below. how can we achieve this? Regular front-end performance optimization no matter what background technology your website is based on
We all hope that when someone accesses our WordPress website, we can quickly see the article, but there are no basic optimization skills below. how can we achieve this?
Regular frontend performance optimization
No matter what background technology your website is based on, regular HTML, CSS, JavaScript, and other files will always be generated and sent back to the client when accessed by visitors. To speed up your website, you can first optimize it from the front-end.
Front-end performance optimization is very deep and involves many techniques and methods. However, you may be a webmaster rather than a professional front-end engineer, so here I will summarize only a few basic but very effective front-end performance optimization skills:
1. compressing images: It takes a lot of time to download images when the web page is opened. If you compress these images or use other techniques (such as lazy load) this can reduce the time. Practice has proved that the jpg image is compressed by 80%, which not only ensures that the quality of the image is invisible but also reduces the size. for images in png format, TinyPNG can be used for compression.
2. Merge Files: The files here mainly refer to CSS and JavaScript files. for each CSS and JavaScript file on the page, the browser will have one more HTTP request and one more wait time. Ideally, there is only one CSS or JavaScript file, and the file size is as small as possible. we recommend that you use the WP Minify plug-in. If you have the ability, you can also combine icons and small images to make them CSS Sprite.
3. using CDN: If your server is located in Beijing, local access to Beijing will be very fast, but visitors in Guangdong may feel slow due to distance and line problems. Mature CDN service providers all over the country will have servers. if you put static files on it and access your website in Guangdong, the files will be downloaded from servers near Guangdong, in addition, CDN servers and bandwidth have been optimized for downloading, and the speed will generally exceed your server, which can greatly increase the speed. Currently, we generally recommend using Qiniu Cloud storage to accelerate static files, here is the WordPress plug-in: Qiniu image storage WordPress plug-in.
For ordinary webmasters, you can understand this. next we will talk about the optimization on the WordPress site.
Install cache plug-ins for WordPress
Cache is a very important thing to speed up. When you access a website and perform cache optimization, some images, CSS and JS files will be cached to your computer. During your next visit, the browser finds that these files in the cache have not expired and immediately calls them from the cache, so that they will not be downloaded from your server. In this way, you only need to download a few KB of text you write and it will be OK. of course, the speed will be faster.
WordPress cache depends on the degree of support of your server. if your server has installed the memory cache components, installing the Memcached plug-in is optimal. if it is a virtual host, we recommend that you install WP Super Cache.
Cache using the. htaccess file
The above is cache by installing plug-ins. if you do not want to install plug-ins, you can use the following method for caching.
Modify the following code according to your needs and put it in the. htaccess file under the root directory of your WordPress site:
# Cache validity period: 1 year
Header set Cache-Control "max-age = 29030400, public"
# Cache validity period: 1 week
Header set Cache-Control "max-age = 604800, public"
# Cache validity period: 2 days
Header set Cache-Control "max-age = 172800, proxy-revalidate"
# Cache validity period: 1 minute
Header set Cache-Control "max-age = 60, private, proxy-revalidate"
Note: Although the cache is useful, the longer the cache time, the better. If some static files do not change their content for a long time, you can set a longer time. For some dynamic files that are frequently modified, you need to set a shorter time. A friend's blog was not updated for a month. after asking him a question, he realized that the cache settings were wrong. as a result, the content was still a long time ago.
Reduce database queries
A dynamic website must perform some queries on the database, and each query requires a database connection, and then waits for the database to return data and output it. This process is a waste of time. WordPress has a lot of unnecessary query and unused features, which can be accelerated.
You can use the following code to check the number of queries created by WordPress. you can copy the query to the functions. php file under the topic directory to view the related information at the bottom:
Add_action ('WP _ footer ', 'wpjam _ page_speed ');
Function wpjam_page_speed (){
Date_default_timezone_set (get_option ('timezone _ string '));
$ Content = '['. date ('Y-m-d H: I: s t'). ']';
$ Content. = 'Page generation time ';
$ Content. = timer_stop ($ display = 0, $ precision = 2 );
$ Content. = 'query ';
$ Content. = get_num_queries ();
$ Content. = 'sub ';
If (! Current_user_can ('admin') $ content =" ";
Echo $ content;
}
As for how to optimize this part, I love boiled fish with a lot of techniques to Disable useless functions. you can search for them as needed.
Find a reliable host
Finding a reliable host is the most effective. The best optimization result was put on a server with frequent traffic and broadband, which is similar to a telephone line. it must be very slow to open. Choosing a host is a complicated and huge piece of content. If the budget is sufficient, you can select a host such as Media Temple. Generally, you are advised to use the Bluehost virtual host.