SoFunction
Updated on 2025-04-13

Methods to analyze and optimize pages with YSlow


6. Put JS at the bottom put Javascript scripts at the bottom to load them as much as possible.

At first, I thought that Javascript scripts should be placed at the bottom of the page to load as much as possible, which means that all JS scripts should be placed at the bottom. Later I found that this is not exactly the case. The scripts referred to here refer to those scripts that need to be executed during the loading process. Therefore, the general way to deal with them is to introduce JS links at the head of the page and execute the JS script program at the bottom of the page. Why do it? Haha, it is actually very simple. In order to achieve the maximum download parallelism, the things you do in the early stage of page loading are best to download, HTML download, CSS download, JS download, and then implement page rendering and JS scripts to run after the download is completed. We still need to work hard on this aspect. We run some scripts during the loading process of many pages. Perhaps it is to implement some functions. There is no way, but there may be a better way to replace them. . .

7. Avoid CSS expressions Avoid CSS expressions

In fact, running expressions in CSS is similar to running a large number of JS scripts during page loading. Perhaps it is slower and incompatible. Although it can make our page logic much simpler, we can completely abandon it. Our page basically did this point. But to be honest, CSS expressions, hehe, I didn't know that this was the case before. Shame. Ha ha.

9. Reduce DNS lookups As few DNS lookups as possible.

What we did not do very well in this. Level D, there are 9 domain names, generally not more than 4. However, this is mainly a problem with the server architecture, and we can't do anything about it. Now there are several advertising domain names on the homepage alone, such as Haoye advertising domain names, Yahoo advertising domain names, Taobao store advertising domain names, and domain names. If we remove these, we are actually enough, one main domain name, one picture, one STYLE, and at most IFREAM is exactly 4.

10. Miniify JS compresses Javascript code.

I have been paying attention to this a long time ago and have also found a good compression tool, yuicompressor, a JAVA compression package developed by Yahoo America. The compression is quite perfect. Not only does the spaces and line breaks between the code are removed, but also simplified the variable names and northern method names, which inadvertently realizes the role of obfuscating scripts. Now we have only achieved JS merge and did not align and compress. If I use yuicompressor to compress manually, although JS compression is implemented, it doubles the amount of maintenance we have to maintain because we need to maintain 2 sets of JS scripts, one set is before compression (for debugging), and the other set is after compression (for publishing to the Internet), and we must ensure that the two sets of code are consistent. So the most perfect way is to implement JS script merge when publishing, compress it with yuicompressor, and then publish it until the evening, moving the key points to the time of publishing, so we only need to care about a set of JS scripts (the version before release). And I think this plan is completely actionable.

11. Avoid redirects Avoid redirects (jump)

How to understand this?

A practice we often encounter is that after the registration is successful, Wangwang will have a page prompt "You have successfully registered and will automatically jump to the XX page in 3 seconds." I just found it very strange, why don’t you jump directly to the page you should go to? There is another type that we are all very familiar with. Generally, the links to our page are written as: Or/, someone may ask, is there any difference? I will tell you clearly, there is! If the URL received by the server is, it will automatically redirect to /. Although the homepage of Alibaba Chinese website was opened in the end, the former took one more step than the latter and redirected, which obviously wasted a certain amount of time. So when we add URL links in the future, don't forget to add the last "/".

12. Remove duplicate scripts

There is actually nothing to say about this. Everyone should abide by it unconditionally, but the more obvious and simple the thing is, we often cannot do it well. Of course, there are many reasons, the project time is too tight, etc., which leads to the code being messy and many repetitive places. In fact, everyone knows that heavy burden is not good, but fortunately, there are not many script codes on our page (at least one page, haha). However, I hope that we not only have to make a page script not repeated, but also to make N pages, and the scripts must be reused.

ETags seems to be a server-side configuration problem. I don’t understand it very much, so I won’t talk nonsense, for fear of misleading everyone.

There are 13 in total, but after reading YAHOO's official instructions, it seems that there is also an AJAX CACHE (AJAX cache). I think this is very important. With the widespread application of AJAX, the concept of AJAX cache must always be in our minds. AJAX is a good thing, but repeated data and endless application to the background is definitely a mistake (not only in terms of speed but also in terms of server pressure). Therefore, we have to cache the data we have applied for. When it is used for the second time, we will directly withdraw it from the cache and do not access our precious server resources. In fact, this idea is not only suitable for AJAX, but should be considered in all applications with data reuse.

The analysis of YSLOW is over here. Perhaps some places are not very correct, and some people analyze it earlier and better than me, but these are indeed what I have accumulated and discovered from work, and many of them are actually applied to work. By the way, hehe, after the LIST page is optimized, the YSLOW score in version 0.92 will reach 76 points, or even 80 points, which is equivalent to more than 90 points in version 0.8. However, after all, the rating is rating, and the key is speed.