Getting things done is good but getting things done in better way is what matters most. Everyone wants to make their website to be faster, lighter. No one likes slow website. In order to make our website faster we have to set some best practices standards and every teammate should follow that.
- VanillaJS is always quicker than using a library. Use VanillaJS as possible if you want highest performance.
- Minimize DOM manipulation since it is a performance consuming task.
- Minimize number of HTTP calls. Try to use cached HTTP response.
- Use lazy loading of resources as much as feasible.
- Avoid broadcasting and listening the events.
- Avoid adding global variables and global methods.
- Declare variables outside of loop.
- Place scripts at the bottom of your web page.
- It will help in speeding up the web page loading.
With great power, comes great responsibility.
=== instead of
- It makes sure that comparison is type safe.
3. Whenever we create any variable, we should try to make it as private as possible. It will help us to avoid name collision with global variables and will provide encapsulation.
4. Use editor plug-in for JS Hint. It will highlight many errors and warnings which will help us to avoid bugs.
null/undefined checks wherever possible.
Category: Organised Codebase
- One file = One Responsibility.
- Don’t use short-hand. Even though there is only one statement in a condition block or loop block, it should be enclosed by curly braces.
3. Use configuration instead of hard coding.
4. For defining strings, use single quotes instead of double quotes.
5. Add comments on method level and conditions (if conditions are complex).
6. Always use semicolons to end the statement.
7. Separate file names with dots and dashes.
8. Remove unused and commented code. Remove unused libraries and their references.
Originally published at https://yuvi1422.blogspot.com on July 20, 2019.