First started on fxm5547's blog
format
No need to add after each sentence js; assignment=Add a space before and after the number Example:
const RECEIVE_ZEN = 'RECEIVE_ZEN'
const REQUEST_ZEN = 'REQUEST_ZEN'
const CLEAR_ZEN = 'CLEAR_ZEN'
Copy code
Use Babel to write ES6/7 code
ES6/7 has added a lot of new features, so that we can better write javascript BabelWe can write ES6/7 and finally compile to ES5 to ensure that there are no compatibility issues.
Minimize the use of jQuery
jQuery has slowly faded out of our sights youmightnotneedjquery You-Dont-Need-jQuery
Use functional programming
JS Functional Programming Guide Javascript functional programming style
Using the ES6 module mechanism
Introducing import foo from 'module' export
const foo = {
...
}
export default foo
Copy code
Defer and async
<script src="script.js"></script> Without defer or async, the browser will immediately load and execute the specified script, "immediately" means before rendering the document element under the script tag, that is, without waiting for the follow-up The loaded document element is loaded and executed when it is read.
<script async src="script.js"></script> With async, the process of loading and rendering subsequent document elements will be done in parallel (asynchronous) with the loading and execution of script.js.
<script defer src="script.js"></script> With defer, the process of loading subsequent document elements will be done in parallel with the loading of script.js (asynchronous), but the execution of script.js will be done after all elements have been parsed, before the DOMContentLoaded event fires. carry out.
The difference between the two is when the script is executed after it is downloaded. Obviously defer is the closest we have to the application script loading and execution requirements.
The key point about defer is that it executes the script in the order of loading, which is a good use of this.
Async is a master of out-of-order execution. Anyway, the loading and execution of the script is tight, so no matter what order you declare, as soon as it is loaded, it will execute immediately.
Think about it, async is not very useful for application scripts because it doesn't consider dependencies at all (even at the lowest level of execution), but it's for scripts that don't depend on any scripts or are not dependent on any scripts. Very suitable, the most typical example: Google Analytics
So most of the places where we load scripts can be replaced with defer.