Home Web Front-end JS Tutorial What are the specifications for front-end monolithic coding?

What are the specifications for front-end monolithic coding?

Mar 19, 2018 am 10:42 AM
Which coding specification

This time I will bring you what are the specifications for front-end monomer coding, and what are the precautions for using front-end monomer coding specifications. Here are practical cases, let’s take a look.

Whether it is front-end or back-end code, coding standards are particularly important, especially in large projects. Standardizing the code, format, and requirements at the beginning will reduce a lot of workload. Conducive to the later maintenance of the code.

##1## Common - Writing Standards Use tab for indentation, set tab to 4 spaces##910## HTML-Writing specification Attributes: 12 HTML-Writing Normative Encoding 1 : 13Encoding 2:## CSS-writing specification The path in the url() function is not quoted. Such as background: url(bg.png);24 CSS-writing specification When the length is 0, the unit must be omitted. Such as padding: 0 5px##252627281.font-family Click "Western font in front, Chinese font in back", "Good effect (high quality/more efficient)" The fonts that meet the needs) are written first, and the fonts with average effects are written in the order of "after". Finally, a general font family (serif / sans-serif) must be specified; Font size: Naming: , and function names must be named in camel case; ## Sanyuan For conditional judgment (shortcut method of if), use the ternary operator to assign or return statements to avoid using them in complex situations. 45 JS-Program Smoothness String Use single quotes (') uniformly and do not use double quotes ("), which is very beneficial when creating HTML strings: such as ##46##50 JS-logical correctness Whether the query results are sorted. 51 JS-logical correctness Query area The total number of entries should be the total number of all data currently queried. Instead of the number of displayed items on the current page##52
Front-end single coding specification table
No

## Category

Verification content
##page design

The list title is displayed in the center.
2 Page design Query data area data display Style:
1. Indefinite length Chinese, indefinite length English, indefinite length Chinese and English, indefinite length English numerals on the left
2. Fixed length, fixed value data Center, date, time, serial number in the center
3. Amount: right
3 Common-writing standardization Whether each file header has correct comments
4 Common-writing standardization Whether each function has correct comments
5 Common-writing standardization Each configuration filewhether the relevant content has comments
6 Common-writing standardization Each logical block Are there comments
7 Common-writing norm Are there any unused variables and references?
##8
## HTML -Writing specification Tag 1: 1. Tag names must use lowercase letters, such as

;
2. For tags that do not need to be self-closing, self-closing is not allowed, such as input, br, img, hr, etc.;
3. For closing tags specified in HTML5, no self-closing is allowed. Allows closing tags to be omitted.
HTML-Writing Normative Tag 2 : 1 The use of tags must comply with tag nesting rules. For example, p must not be placed in p, and tbody must be placed in table.
2. The use of HTML tags should follow the semantics of the tags. Common tag semantics p - paragraph
h1,h2,h3,h4,h5,h6 - hierarchical title
strong,em - emphasis
ins - insert
del - delete
abbr - abbreviation
code - code identification
cite – cite the title of the source work
q – cite blockquote - a paragraph or long quote
ul - unordered list
ol - ordered list
dl,dt, dd - Definition form
##11 1. Attribute names must use lowercase letters;
2. Attribute values ​​must be surrounded by double quotes;
3. It is recommended that custom attributes be prefixed with xxx- and data- is recommended, such as
    .
    1. Use HTML5 doctype to enable standard mode. It is recommended to use uppercase DOCTYPE.
    2. The page must contain the title tag to declare the title.
    3.title must be a direct child element of head and immediately after the charset declaration.
    Example

    Page title

    ## HTML-writing standardization

    1. Ensure that the favicon is accessible, (place the favicon.ico file in the root directory, use link Specify favicon)
    such as;

    2. If the project is mobile or

    responsive layout

    , the viewport of the page must be specified.

    14 HTML-writing standardization Introduction:
    1. When introducing CSS, you must specify rel="stylesheet", such as ;
    2. Import There is no need to specify the type attribute when using CSS and JavaScript (there is a default value);
    3. Introduce all CSS resources needed for the page in the head. JavaScript should be placed at the end of the page, or loaded asynchronously. (Placing the script in the middle of the page will block the rendering of the page).
    15 HTML-Writing Standards

    Picture:
    1. Prohibit the src value of img from being empty. Lazy loading images should also add the default src (an empty src will cause the page to be reloaded); Add unnecessary title attribute, (excess title affects Picture viewing experience, and increased page size);

    3. Add alt attributes to important pictures;

    4. If you need to download Images are implemented using img tags, and images without download requirements are implemented using CSS background images.

    16 HTML-Writing Standards Form:
    1. A control with a text title must use the label tag to associate it with its title;
    2. When using the button element, the type attribute value must be specified;
    3. The buttons responsible for the main functions should be placed first in the DOM (recommended, subject to design).
    17 HTML-Writing Standards Video and Audio:
    1. Prioritize using the audio and video tags to define audio and video elements in browsers that support HTML5;
    2. Only enable audio when necessary Automatic playback of videos;
    3. Provide a description inside the object tag indicating that the browser does not support the tag, such as DO NOT SUPPORT THIS TAG.
    18 CSS-Writing Normative Style Line The length of each line must not exceed 120 characters unless the line is indivisible.
    19 CSS-writing specification Naming:
    1.class and id must be in all lowercase letters, and words are separated by - (hash);
    2.class and id must represent the corresponding module or The content or function of the component must not be named with style information. Words such as left, right, center, red, black, etc. appear alone in the name;
    3.class must be added with the corresponding prefix (avoid Global pollution), such as g-represents global style, m-represents module style, ui-represents component style, etc. The details are subject to project regulations;
    4. A single style is not allowed to appear! important;
    5. Class is not allowed. It is only used to let JavaScript select certain elements and create a class without style information (using id);
    6. Element The id must ensure that the page is unique;
    7. Same page, different tags, avoid using the same name and id (the same tag can be used).
    20 CSS-Writing Standards When a When a rule contains multiple selectors, each selector declaration must be on its own line.
    21 CSS-Writing Standards # #Values ​​in the attribute selector must be surrounded by double quotes. Such as input[name="acd"] {......}
    22 CSS-Writing Standardization When the value is a decimal between 0 - 1, the 0 in the integer part is omitted. Such as opacity: .8
    23
    CSS-writing specification Style code should be saved independently in a file with the suffix .css. Interline styles are not allowed except under special circumstances.
    CSS-writing specification RGB color Value must use hexadecimal notation form #rrggbb. rgb() is not allowed.
    CSS-writing specification Color: 1. RGB color values ​​must use hexadecimal notation #aabbcc, rgb() is not allowed;
    2. When color values ​​can be abbreviated, they must Use abbreviations; such as #fff,#000
    3. Named color values ​​are not allowed for color values; such as red green and other uncertain values
    4. Color Values ​​all use lowercase English letters.
    CSS-Writing Standardization Font 1 : 1. The font family name in the font-family attribute should use the English Family Name of the font. If there are spaces, they must be placed in quotation marks. The use of Chinese characters is strictly prohibited. Example font-family: "Microsoft YaHei";
    Font Operating system Family Name
    宋体(中易宋体) Windows SimSun
    Black body (Zhongyi Hei body) Windows SimHei
    Microsoft YaHei
    Microsoft YaHei
    ##Microsoft JhengHei华文黑体                                                                                                                                                                                               using using using using using   using   using   using ‐ ‐                         –                                                          文 Quan Yi Micro Hei Linux  WenQuanYi Micro Hei

    ##29
    CSS-writing standardization
    Font 2: Example font-family: Arial, sans-serif;
    30
    ## CSS-writing specification
    1. Chinese content that needs to be displayed on the Windows platform, its font size should be no less than 12px; 2. Chinese content that needs to be displayed on the Windows platform , do not use font-style other than normal.
    31
    JS-Writing Standardization
    Common naming: camel case naming thisIsAnApple, Pascal naming thisIsAnApple, underline naming this_is_an_apple, and underscore naming this-is-an-apple 1. Method /Attribute names, variable names, parameter names, namespace 2. Class names, enumeration names,
    constructors , Pascal naming must be used;
    3. Constant names and enumeration attributes: all uppercase underline nomenclature must be used, such as IS_DEBUG_ENABLED; 4 .Private (protected) members (properties, functions, etc.): must start with underscore _;
    5. Boolean type should start with is, has, etc. to indicate its type; 6. Naming also requires attention to semantics. For example, variable names should use nouns, function names should use verb-object phrases (getAccListData), and class names should use nouns.
    32 JS-Writing Standards JavaScript program It should be saved independently in a file with a .js suffix.
    33 JS-Writing Standards Avoid every Line exceeds 80 characters.
    34 JS-Writing Standards Try to reduce it as much as possible When using global variables, do not let local variables overwrite global variables.
    35 JS-writing specification can be used In the case of a common function, whether the common function is used.
    36 JS-Write normative statements:
    1. Each line contains at most one statement, put; (semicolon) at the end of each simple statement;
    2.return statement
    Do not use ( ) (brackets) to enclose the return value in a return statement with a return value. If an expression is returned, the expression should be on the same line as the return keyword to avoid accidentally adding a semicolon;
    3. Avoid using the continue statement, which can easily make the logic process of the program obscure. Difficult to understand;
    4.eval is the most easily abused method in JavaScript, avoid using it.
    37 JS-Writing Normative ES5 syntax The code must be wrapped into an IIFE (Immediately-Invoked Function Expression) to create an independent and isolated definition domain to prevent the global namespace from being polluted.
    38 JS-Writing Normative in the code Add js strict mode 'use strict'
    ##39 JS-writing standardization Variable declaration: Use var or let to declare variables. If you do not specify a variable, it will be implicitly declared as a global variable, which will make it difficult to control the variable.
    40 JS-Program Smoothness Wisely Using true and false judgment, if(a == true) is different from if(a). This judgment will convert it into true or false through special operations. The following expressions all return false: false, 0, undefined, null, NaN, (empty string).
    41 JS-Program Smoothness Avoid creating functions in loops. Adding functions to simple loop statements can easily form closures and cause hidden dangers.
    42 JS-program smoothness Avoid When declaring a function within a statement block, a syntax error will be reported in strict mode.
    43 JS-Program Smoothness Using arrays and object literals instead of arrays and object constructors. The array constructor makes it easy to make mistakes with its arguments.
    44 JS-Program Smoothness
    var msg = 'This is some HTML

    '.
    JS-Program Smoothness Do not use redundant programs. The following examples are used as reference: ・There are unused subroutines
    ・Repeated initialization
    ・Define unused variables
    ##47 JS-logical correctness No strange logic (empty functions, unprocessed branches, etc.)
    48 JS-Logical correctness The string length of the text input box is limited based on two points: 1. Whether it is required by the business; 2. Whether the database field length meets the requirements
    49 JS-logical correctness After the query is completed, query The conditions should remain in the corresponding input boxes
    JS-logical correctness The query condition input box should remove the leading and trailing spaces before querying
























































































































    # I believe you have mastered the method after reading the case in this article. For more exciting content, please pay attention to other related articles on the php Chinese website!


    Recommended reading:


    The solution to the problem that the text in the Safari browser select drop-down list is too long and does not wrap


    ##HTML and CCS Combine


    The above is the detailed content of What are the specifications for front-end monolithic coding?. For more information, please follow other related articles on the PHP Chinese website!

    Statement of this Website
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

    Hot AI Tools

    Undresser.AI Undress

    Undresser.AI Undress

    AI-powered app for creating realistic nude photos

    AI Clothes Remover

    AI Clothes Remover

    Online AI tool for removing clothes from photos.

    Undress AI Tool

    Undress AI Tool

    Undress images for free

    Clothoff.io

    Clothoff.io

    AI clothes remover

    Video Face Swap

    Video Face Swap

    Swap faces in any video effortlessly with our completely free AI face swap tool!

    Hot Tools

    Notepad++7.3.1

    Notepad++7.3.1

    Easy-to-use and free code editor

    SublimeText3 Chinese version

    SublimeText3 Chinese version

    Chinese version, very easy to use

    Zend Studio 13.0.1

    Zend Studio 13.0.1

    Powerful PHP integrated development environment

    Dreamweaver CS6

    Dreamweaver CS6

    Visual web development tools

    SublimeText3 Mac version

    SublimeText3 Mac version

    God-level code editing software (SublimeText3)

    11 common classification feature encoding techniques 11 common classification feature encoding techniques Apr 12, 2023 pm 12:16 PM

    Machine learning algorithms only accept numerical input, so if we encounter categorical features, we will encode the categorical features. This article summarizes 11 common categorical variable encoding methods. 1. ONE HOT ENCODING The most popular and commonly used encoding method is One Hot Enoding. A single variable with n observations and d distinct values ​​is converted into d binary variables with n observations, each binary variable is identified by a bit (0, 1). For example: the simplest implementation after coding is to use pandas' get_dummiesnew_df=pd.get_dummies(columns=[‘Sex’], data=df)2,

    How many bytes do utf8 encoded Chinese characters occupy? How many bytes do utf8 encoded Chinese characters occupy? Feb 21, 2023 am 11:40 AM

    UTF8 encoded Chinese characters occupy 3 bytes. In UTF-8 encoding, one Chinese character is equal to three bytes, and one Chinese punctuation mark occupies three bytes; while in Unicode encoding, one Chinese character (including traditional Chinese) is equal to two bytes. UTF-8 uses 1~4 bytes to encode each character. One US-ASCIl character only needs 1 byte to encode. Latin, Greek, Cyrillic, Armenian, and Hebrew with diacritical marks. , Arabic, Syriac and other letters require 2-byte encoding.

    Knowledge graph: the ideal partner for large models Knowledge graph: the ideal partner for large models Jan 29, 2024 am 09:21 AM

    Large language models (LLMs) have the ability to generate smooth and coherent text, bringing new prospects to areas such as artificial intelligence conversation and creative writing. However, LLM also has some key limitations. First, their knowledge is limited to patterns recognized from training data, lacking a true understanding of the world. Second, reasoning skills are limited and cannot make logical inferences or fuse facts from multiple data sources. When faced with more complex and open-ended questions, LLM's answers may become absurd or contradictory, known as "illusions." Therefore, although LLM is very useful in some aspects, it still has certain limitations when dealing with complex problems and real-world situations. In order to bridge these gaps, retrieval-augmented generation (RAG) systems have emerged in recent years. The core idea is

    Several common encoding methods Several common encoding methods Oct 24, 2023 am 10:09 AM

    Common encoding methods include ASCII encoding, Unicode encoding, UTF-8 encoding, UTF-16 encoding, GBK encoding, etc. Detailed introduction: 1. ASCII encoding is the earliest character encoding standard, using 7-bit binary numbers to represent 128 characters, including English letters, numbers, punctuation marks, control characters, etc.; 2. Unicode encoding is a method used to represent all characters in the world The standard encoding method of characters, which assigns a unique digital code point to each character; 3. UTF-8 encoding, etc.

    Which games are suitable for playing with i34150 and 1G independent graphics (which games is suitable for i34150) Which games are suitable for playing with i34150 and 1G independent graphics (which games is suitable for i34150) Jan 05, 2024 pm 08:24 PM

    What games can be played with i34150 with 1G independent graphics? Can it play small games such as LoL? GTX750 and GTX750TI are very suitable graphics card choices. If you just play some small games or not play games, it is recommended to use the i34150 integrated graphics card. Generally speaking, the price difference between graphics cards and processors is not very big, so it is important to choose a reasonable combination. If you need 2G of video memory, it is recommended to choose GTX750TI; if you only need 1G of video memory, just choose GTX750. GTX750TI can be seen as an enhanced version of GTX750, with overclocking capabilities. Which graphics card can be paired with i34150 depends on your needs. If you plan to play stand-alone games, it is recommended that you consider changing the graphics card. you can choose

    PHP coding tips: How to generate a QR code with anti-counterfeiting verification function? PHP coding tips: How to generate a QR code with anti-counterfeiting verification function? Aug 17, 2023 pm 02:42 PM

    PHP coding tips: How to generate a QR code with anti-counterfeiting verification function? With the development of e-commerce and the Internet, QR codes are increasingly used in various industries. In the process of using QR codes, in order to ensure product safety and prevent counterfeiting, it is very important to add anti-counterfeiting verification functions to the QR codes. This article will introduce how to use PHP to generate a QR code with anti-counterfeiting verification function, and attach corresponding code examples. Before starting, we need to prepare the following necessary tools and libraries: PHPQRCode: PHP

    Variable naming conventions required in Python learning Variable naming conventions required in Python learning Jan 20, 2024 am 09:03 AM

    Variable naming conventions you need to know when learning Python An important aspect when learning the Python programming language is learning how to name and use variables correctly. Variables are identifiers used to store and represent data. Good variable naming conventions not only improve the readability of your code, but also reduce the possibility of errors. This article will introduce some commonly used variable naming conventions and give corresponding code examples. Use Meaningful Names Variable names should have a clear meaning and be able to describe the data stored in the variable. Using meaningful names allows it to

    What are the hdb3 encoding rules? What are the hdb3 encoding rules? Aug 29, 2023 pm 01:38 PM

    The coding rules are: 1. If the previous code is 0 and the current data bit is 0, the code is 0; 2. If the previous code is 0 and the current data bit is 1, the code is bipolar pulse (+A or - A), and the counter is increased by 1; 3. If the previous code is 1 and the current data bit is 1, the code is 0, and the counter is increased by 1; 4. If the previous code is 1, the current data bit is 0, The encoding method is determined based on the parity of the counter. If it is an even number, the encoding is (+B or -B). If it is an odd number, the encoding is zero level and the counter is cleared and so on.

    See all articles