Sometimes we implement multiple external links which points to the same resource. For example in one of our websites we have
Both of these result to
https://www.instagram.com/static/bundles/es6/EmbedSDK.js/363a6c0267bf.js
Thus the website made 3 network requests for the same resource 😅😅
The solution?
I observed that implementing the final result i.e.
https://www.instagram.com/static/bundles/es6/EmbedSDK.js/363a6c0267bf.js
reduced the number of network calls from 3 to 1 ✌
Read more: https://blog.nordible.com/Website-network-load-optimization-tip/
It changes
p { padding-top: 10px;
padding-right: 20px;
padding-bottom: 30px;
padding-left: 40px; }
to
p{padding:10px 20px 30px 40px}
Changes colors (e.g. #336699
) to it’s shorter forms.
p { margin-top: 10px;
margin-right: 20px;
margin-bottom: 30px;
margin-left: 40px; }
to
p{margin:10px 20px 30px 40px}
and many more.
The playground is here: https://cssnano.co/playground/
Plugin: https://www.npmjs.com/package/cssnano
When JavaScript evaluates 0 && anything the result will always be 0 because 0 is falsy, so it doesn’t evaluate the right side of the &&
console.log(0 && true) // 0 - falsy, right side not evaluated
console.log(0 && false) // 0 - falsy, right side not evaluated
console.log(false && true) // falsy, right side not evaluated
console.log(false && false) // falsy, right side not evaluated
Look at these too:
console.log(1 && true) // true, right side evaluated
console.log(1 && false) // false, right side evaluated
console.log(1 && false) // false, right side evaluated
console.log(1 && false) // false, right side evaluated
The solution? Use a ternary to be explicit.
Read more: https://blog.nordible.com/Javascript-Tip-Use-Ternary-Instead-Of-And-And/
Sometimes we need to check the existence/truthiness of properties on objects/classes. For example, this is how we generally write it:
if (family && family.mother && family.mother.child){
console.log(family.mother.child);
}
This can be written in short like this:
console.log(family?.mother?.child);
The magical operator being used here i.e. ?.
is called the Optional chaining operator.
Read more: https://blog.nordible.com/Javascript-Tip-Use-Optional-Chaining/
Shorten code for decimal numbers using exponential notation instead of 0s
In javascript, N number of 0s after a number can be replaced with eN
Example:
5e4 = 50000
7e2 = 700
7e0 = 7
7e1 = 70
Read more: https://blog.nordible.com/Javascript-Trick-Use-Exponential-Number-Notations/
For loops can be shortened and cleaned. Let’s see an example:
Long-form:
const friends = ['amar', 'akbar', 'anthony'];for (let i = 0; i < friends.length; i++){ console.log(friends[i]);}
Short / clean form:
const friends = ['amar', 'akbar', 'anthony'];for (const friend in friends){ console.log(friend);}
Read more: https://blog.nordible.com/Javascript-Best-Practices-Use-For-In-Loops/
Check for synchronous code in Nodejs process:
The command-line utility --trace-sync-io
tells us about synchronous tasks.
Example use:
node --trace-sync-io index.js
Read more: https://blog.nordible.com/Nodejs-Diagnosis-Tip-Check-For-Synchronous-Code/
Sometimes we need to assign only truthy (not undefined/null/empty) values to our variables.
It is done like this:
if (myVar !== null && myVar !== 'undefined' && myVar !== '') {
yourVar = myVar;
}
else {
yourVar = 'new default value';
}
This can be optimized as:
yourVar = myVar || 'new default value';
Read more: https://blog.nordible.com/Javascript-Best-Practices-Shortify-Falsy-Truthy-Checks/
A. Provide constructive criticism for code improvement to team members
B. Try to get everyone to give PR comments (or at least have a look at other’s code changes) irrespective of anything
C. Learn from others code
D. Teach better coding practices with your PR comments
E. If needed, decline PR request in worst-case scenarios
F. Challenge PR comments in a constructive way as all improvement suggestions might not apply
Read more: https://blog.nordible.com/Coding-Best-Practices-Implement-Serious-Code-Review/
This is basically a checklist of what to expect when renting a new home in Mumbai. I have written it exclusively for me to reference.
The Basics