This content originally appeared on DEV Community and was authored by Ashok Sharma
Web development projects range from highly complex to relatively simple. No matter the complexity of the project you're dealing with, it's inevitable that you'll have to deal with errors and debug your code. Coding standards and best practices make this task a lot easier.
Aside from making debugging easier, following best practices also guarantees cleaner code and reduces unnecessary errors. They’re a part of skills that every developer must possess. Here are 9 best practices that every web developer must follow in 2021.
1. Sort div Tags
It's common to see multiple div tags closing at the bottom of a page. While divs are cleaner than tables, leaving them unsorted only results in a mess that is hard to clean up. Indentation is a good way to organize tag closes.
However, the best way to organize your div tags is to comment on which one you're closing. For example, adding a comment such as <!--#header -- > helps the reader understand which tag you're closing.
2. Use CSS Resets
CSS resets are a common practice in web development, but it's surprising how many beginner developers neglect to do this. The result is cross-browser rendering issues that destroy UX.
A CSS reset removes individual styling from all elements, and this leaves no room for browsers to override your style element with their defaults.
3. Avoid @import
@import was a popular choice for many developers when it came to importing CSS files. Including a stylesheet into another is easy with this directive. Alternatively, CSS files can be included in HTML documents as well.
However, as browsers drop default import support, developers have to find other ways to include external HTML files within the main file. Renaming the external HTML file extension to .shtml and using server-side includes (SSI) within the HTML is the best approach. Note that the file with the SSI command must be named with the shtml extension.
4. Remember Accessibility
The web is becoming a far more inclusive place, and every website should cater to differently-abled people. In the past, developers had to customize and reconfigure every element to make their websites more accessible. One classic example is adding Alt text to all images so that screen readers will understand how to interpret and explain a photo to a screen reader user.
These days, AI-based web accessibility solutions by acessiBe automate the process. Their AI technology scans the site every 24 hours in search of new content that has to be made accessible. The result is full ADA and WCAG compliance and continued support as your website grows.
5. Compress and Optimize Images
Optimizing images for the web is difficult even if you use Photoshop's "save for web" commands. If you aren't worried about your site's bandwidth, then unoptimized images aren't an issue. However, when creating business websites, developers almost always have to keep bandwidth in mind.
Tools like TinyJPG and compressjpeg are excellent free choices that developers can use. Smush it and RIOT are great paid options.
6. Don't Mix CSS With HTML and Javascript
HTML's purpose is to organize web documents by defining headers, footers, and so on. Front-end developers sometimes use deprecated HTML attributes to style elements. However, this often precipitates into developers using the style attribute to insert CSS directly into HTML.
This practice is fine in development or for a quick test, but it's hardly suitable for production. Avoid using the style attribute to insert CSS since this goes squarely against the spirit of CSS. Similarly, inserting Javascript into HTML is poor practice.
Using unobstructed Javascript might seem tedious, but it results in cleaner HTML and better code results.
7. Conditional Commenting
Microsoft has announced the end of support for Internet Explorer which will make this requirement redundant in a few years. However, for now, it still exists and this means developers have to account for web pages being displayed on this obsolete browser.
There are hacks you can use to customize your code, but the problem is that CSS validation fails. Instead, use conditional comments to target particular versions of Internet Explorer.
8. Use Semantic HTML
HTML is a markup language and is used to create structured documents. Developers should use it to denote headings, paragraphs, and other design elements. It's important to use semantic HTML to give your page more meaning.
Semantic tags make your on-page communication clear to browsers and search engines. They allow for increased customization via the use of well-applied CSS.
9. Build and Test in Parallel
Cross-browser rendering is a huge issue every web developer has to account for. Test your code while you're building it instead of rendering it in one browser and adjusting it for others afterward. You'll save time and find it easier to debug any code.
Digital vector created by freepik - www.freepik.com
This content originally appeared on DEV Community and was authored by Ashok Sharma
Ashok Sharma | Sciencx (2021-06-08T16:09:50+00:00) 9 Web Development Best Practices for 2021. Retrieved from https://www.scien.cx/2021/06/08/9-web-development-best-practices-for2021/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.