Lu songsong: how to improve the running speed of WordPress

Source: Internet
Author: User

When I first bought a host, I was excited and the test speed was also excited. Install WP, toss various themes, toss various plug-ins, and write various blog posts. After a while, the initial burst sensation turned into an egg sensation, and the host speed seemed to be getting slower and slower. Why? A mouse? Some even choose to replace the host.

The above are some of my doubts. Many may have experienced similar tragedies. Most people will deduct the problem to the host service provider and think that its service is becoming increasingly unstable, earning US 100 yuan/year of hard-earned money. The cake is now sent to the nest. On the other side of the river, the host provider complained and went crazy.

Good, the speed of the host itself is indeed the most important factor affecting the speed of the website, but it is also affected by many other aspects. This is why the installation of WP is fast and slow after a while. Willin Kan once wrote a article titled WordPress cannot fly. Some people seem to have misunderstood this article. The full text does not mention the performance of WP's own program design, but mainly mentions the effect of plug-ins and data on WP speed. This is like a Windows system. In fact, it is quite useful. However, because various application software are designed to be relatively poor, the more slow the computer is, the more users give Bill Gates a two hundred and five hat. Looking back at what Willin Kan wants to express may be: WordPress is correct, and the culprit is caused by various additional features. (Personal YY ..)

What should we do? Let's take a look at the picture. This is the analysis and weight of Baidu website speed diagnostic tool for various indicators of website speed loading:

 

If you put the content on WP, You can summarize it into the following more intuitive methods:

Reduce the use of plug-ins

This is the first point. There is a popular saying that "no plug-ins can be solved with code", but the actual situation is that most people often do not have enough code knowledge, and it is even more impossible to do it right, every plug-in is code-based, so this is a typical stand-and-talk solution. A better choice is to use plug-ins that are not needed. The plug-ins are completely clean. Most plug-ins query and generate data, which takes time during page generation. If your host has strict restrictions (to balance resource usage), the time may even become longer than the limit.

Most WP plug-ins load a variety of sharp CSS and JS on the page, and there are two content in website optimization:

1. Reduce HTTP requests. Each access to files such as JS and CSS is an HTTP request. If the agent is used less, the number of HTTP requests is naturally less.

2. Merge CSS and JS files: the first way to reduce HTTP requests is to merge CSS and JS. Loading a 10 KB js file and two 5 kb js files takes different time. Obviously, the latter will take longer. Especially when files are in the same domain name. The js and css of the plug-in are independent. If each of the 10 plug-ins generates one js + one css, plus the topic, the number of css and js files may exceed 30. This .... Too talented.

Although you can also manually merge CSS and JS of these plug-ins into the topic, this method is obviously cumbersome and stupid.

Many people have heard the phrase "delete unused plug-ins", but they do not know why. This is advantageous because WP judges the use of the plug-in every page access. Making WP make fewer judgments is equivalent to making fewer data queries. Free up the burden of it.

Exercise caution when selecting a topic or manually optimizing it

Today, the WP theme is getting more and more attention, and you need to be cautious in the face of these exquisite temptations. Although many themes are beautiful, they are not doing well in optimization. JS, CSS, background images, empty lines, and redundancy all affect the loading speed. However, this does not mean that you cannot select a beautiful theme. Instead, you must manually modify the theme to meet the following requirements:

1. Merge CSS and JS: Merge multiple CSS into one. Merge multiple JavaScript files into one file. This reduces HTTP requests and speeds up rendering time and loading.

2. Merge background images: Use CSS Sprites to merge most background images into one file, which also reduces HTTP requests, reduces file volume, and accelerates rendering time.

3. Reduce Data Query: Do not query data where HTML can be directly output.

4. Reasonable JS and CSS positions: properly place some JS and CSS at the bottom of the webpage.

5. Optimize the background image of the topic. For example, if the image is a pure gray PNG image and a jpg image, the PNG image is obviously smaller in size. For example, the visual difference between a jpg image with a quality of 70 and A jpg image with a quality of 90 is not big, but the size of 90 may be 50% or more higher, this is especially evident in large images. Generally, PNG is used for images with a single color tone or a transparent background, and JPG or GIF is used for Reversed colors. Each format can have different quality options for the selection of quality and volume equilibrium.

Reduce external resource usage

External resources are resources that are not on their own servers. If you use too many external resources, you may encounter the following problems:

1. DNS resolution takes longer

DNS resolution is required for each domain name to work properly. If the content on the website needs to load resources of a.com, B .com, c.com, and d.com at the same time, it takes more time to resolve the DNS of each domain name and establish a connection. Similarly, if your website is a.com and similar domain names such as 1.a.com and 2.a.com are loaded at the same time, the DNS resolution time will also be extended. External resources cannot be completely avoided, but fewer resources are allowed.

2. The loading speed of external resources is uncontrollable.

This is mainly for the content of some foreign sites, such as fickr and twitter. Because of the well-known reasons, loading their resources will obviously slow down the loading speed. Websites in China are relatively fast.

Reduce database queries or use database cache plug-ins

The database query time is like asking the database: "Help me find the film played by Mr. Zhang Cang in those action movies in May last October ". Find the database and give it to you. If 100 requests are sent to it at the same time, the time for searching and feedback is obviously extended.

Many plug-ins require database queries. The above section on plug-ins and topics also mentions optimization code to minimize the number of database queries. If you do not understand, you can consider using the database cache, which can cache the database query content, as if you know in advance what you are looking for, and then sort these items in advance, when I need it, I don't have to go blind in the action movies, but I can give it to me immediately. For example, the famous database Cache plug-in DB Cache Reloaded, but this plug-in has already stopped updating. Foreign users developed another DB Cache Reloaded fix on the basis of its original version. The effect is good.

Note that the database cache plug-in should not be used with the static cache plug-in. Because both of them are data cache content to reduce queries, if used together, it is equivalent to repeated work.

Use static page cache plug-in

Static cache plug-ins and database cache plug-ins are similar in principle. They all sort out the content in advance and generate static files. They are taken out directly when needed, instead of searching and generating them, waste time. Cached static files are basically equivalent to a static image and do not need to execute too much complicated content. My personal recommendation of the Static Page Cache plug-in is WP Super Cache. I love boiled fish once recommended it. It is very powerful (introduction of boiled fish) and easy to operate. Big Cat has written five steps of the use of tutorials.

Use Gzip to compress webpages

Gzip compression can reduce the size of webpages by 20% or more (except for static resources ). Generally, most WP hosts support Gzip on the server and can be automatically compressed. If the server does not automatically compress the page, you must enable it on your own. The WP Super Cache mentioned above contains this function. Or there are

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.