Web Front-end -- code comments you have to make

Source: Internet
Author: User

Haha, have you eaten dumplings during the Dragon Boat Festival today? Or an egg! I am eating and writing. It's so nice! The Dragon Boat Festival is a tribute to Qu Yuan, a great poet who has made great contributions to poetry!

When we write CSS styles, do you habitually write comments in the style sheet? If you are not used to it, we recommend that you try to develop this habit, because when we write CSS style sheets, we must be very clear about the functions or effects of these CSS style sheets, so we will try again in six months or longer.CodeAre you able to see the functions or effects of the code at a glance? Do you need to download the page source code to help you read CSS? If this is the case, you will be miserable, and your CSS code must be very bad. Although you can see to a large extent that the code plays a role in the page, some of the selector you use may not be able to figure out what you want, but one advantage is that CSS is easy to read, it is not easy for people to analyze the CSS writing structure of your page. This means that there is a benefit, but there is a harm. If the disadvantage is greater than the advantage, it is not advisable. Let's talk about the benefits of writing code comments:

It is easy to add comments in CSS code. CSS Comments start with/* and end */. This annotation is used as a comment for the cgrid, because it is used in the C language. The comment can be a single row or multiple rows:

/* Body styles .)
Body {
Font-size: 67.5%;/* set the font size */
}
No.1 add structure comment

When creating a CSS style sheet, the first thing to do is to add a comment block at the beginning of CSS (generally this is not so troublesome, it is purely a personal habit)
/* ------------ Basic style sheet (for wersion4 browsers )--------------------------------
---------------- Date20110604 ------------------------------------------------------------
---------------- Weili. Jia http://www.xxxxxx.com/chuangyuan. Jia @ gmail --------------------------
---------------- Company_xxxxxxx --------------------------------------------------------*/
We know that the browser will automatically ignore these things during parsing, so it is harmless to write some things, and it will provide great convenience for future maintenance or maintenance by others. You may have read this in a Javascript file. Have you ever written it like this? I downloaded the CSS source code from a foreign website and sent an email to him following the prompts in his source code. As a result, he received an email and sent it back to me to discuss CSS knowledge, haha, if we don't mention this, we can give a prompt to the later or ourselves for future changes, and let others find the author of CSS. Why not? Again, this is just my personal habit. I would like to share it with you, but it is not necessary to comment out it.

If the style we write is particularly long, especially when several page style sheets are written in one style sheet, it is even more necessary for us to annotate the structure. Because we don't have that much time to read one line at a time to know what they want to achieve. Why don't we add a comment?

NO2. self-Prompt

Sometimes some special methods may be needed to solve some incompatible problems, such as writing an additional value for some bugs in IE, then, we need to comment out some/* IE6/7bug OK */. In this way, we will be able to avoid accidental deletion during the next maintenance, and it is clear that he wants to express it, if you really don't want others to know what I wrote, it's easy:/* 67iebo */so others don't know what you wrote, I know it means IE6/7 bug OK. But in this case, we will have a fixed comment style. Otherwise, the comment is equal to no comment, in a few months, you will forget what you noted!

NO3. Delete the comment in the style sheet

Never talk to me about the title. Deleting a title does not mean that the title is not all, but simplified as much as possible. Many html/CSS and text editors have the search replacement function. Therefore, it is easy to find unnecessary deletions and replace spaces to reduce CSS file bytes! Some people try to write comments in PHP format and then send the style sheet to the browser. This requires setting the type of the CSS document in A. htaccss file: addtype application/xhttpd-php.css

However, we need to ensure that CSS files can be cached. Otherwise, this method will not speed up access, but slow down. This can be implemented using PHP, but it is complicated. So unless you are very confident, do not do this. Otherwise, it will break you into the eighth-level hell! (I have never used it, and it is not recommended .)
As we know, comments will increase the CSS file, and the loading speed will be somewhat affected! So we can try to make the comments brief and clear! (Recommended for enterprise websites) do not use comments as much as possible for large-scale portal development.

(Like to learn and want to discuss with me a variety of Web Knowledge left your mailbox or contact information, or with me mail 747850255@qq.com reprint Please consciously attach reprinted address, from the blog Park "Opening Audi next year ")

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.