Best Practices of Modern Web Development
- Search Engine Optimization (SEO)
- Accelerated Mobile Pages (AMP)
- User Interface (UI) design
- User Experience (UX)
- Usability
- Accessibility
- Hypertext Markup Language (HTML)
- CSS
- Javascript
- Responsive Designs
- Image
- Cross-device. Google state responsive design is the preferred method of optimization, better for SERP (search engine result page)
- Meta description and page: every page should only have one h1-tag to make the title clear to Google.
- Title tag: use the most important target keyword
<title>SEO | SEO Best Practices | SEO for Front End Developers</title>- Meta description: it is not used for ranking directly, but still important for SEO
<meta name="description” content=”Your page meta description, no more than 160 characters.”/> - Schema markup
- Properly tagged images
<img src="smile-face.gif" alt="Smile face"> - Site speed: if the website speed is slow, google will punish
- User experience: know the goal of website, get potential clients to buy something as quickly and smooth as possible
- Content: should not have duplicate content. Update index and content is good for ecommerce website
- Clean URLs: https://www.example.com/category/product-name
- Semantic markup: not only helps SEO, but also goods for screen readers. It is also benefit the site's visitors and provides them an improved user experience.
- Keep a simple interface: avoid unnecessary elements, clear for labels and error messages, and reduce frustration for users
- Keep web page consistency
- Be purposeful in page layout: draw attention to the most important pieces of information, such as checkout button in an Ecommerce website
- Use color and texture strategically : attention toward or redirect attention away from items using color, light, contrast, and texture to your advantage
- Use typography to create hierarchy and clarity: different sizes, fonts, and arrangement of the text to help increase readability.
- Avoid giving visitors too many options
- Avoid external links: keep users on your website as long as possible
- Make responsive website
- For long text/paragraph, make proper width
- Use common/established/standard design patterns: avoid confusion visitors
- Logo placed in the top left-hand corner
- Navigation links running across the top
- Footer and what type of info they usually contain: social media links and address
- Identify the users and improve design: SEO and usability work together to create persuasive design
- Know your devices screen sizes: in order to maximize the customer's purchase and responsive for viewing on mobile devices
- Support most of browser: Internet Explorer, Mozilla Firefox, Google Chrome, Opera, and Safari
- Find usability errors to improve SEO
- Cut down your load time
- Compress your images to smaller file sizes
- Use CSS for the layout of your website
- Reduce the number of HTTP requests
- Set up browser caching
- 404 Error Page helpful
- Design the page in a brand-cohesive way
- Give visitors an easily way to contact you to inform the error
-
Validate your code: follow Web Content Accessibility Guidelines (WCAG 2.0)
- Perceivable: Information and user interface components must be presentable to users in ways they can perceive
- Operable: User interface components and navigation must be operable
- Understandable: Information and the operation of user interface must be understandable
- Robust - Content must be robust enough that it can be interpreted reliably by a wide variety of user agents, including assistive technologies.
-
Navigate website with a keyboard only
- Tab in a logical order
- Enter, edit, or submit a form
- Left, right, up and down arrow keys to navigate
- Enter key to take an action
-
Text Clarity and concise: double-check your spelling and grammar
-
Don’t rely exclusively on color
-
Provide appropriate alternative text: helpful for people who are blind and rely on a screen reader to have the content of the website
<img src="smile-face.gif" alt="Smile face"> -
Provide headers for data tables
-
Ensure users can complete and submit all forms: Ensure that every form element (text field, checkbox, dropdown list, etc.) has a label and make sure that label is associated to the correct form element using the element
-
Try to avoid slideshow
- Do not use tabular layouts, it is not user friendly for screen readers; only use them when you need to display tabular data
- Try to use percentage for width/height, it is better for responsive website
- Decrease unnecessary tages to reduce page weight
- Quality code: cleaner and concise code, and code weight
- HTML5 Elements: to provide semantic value and make use of HTML5 elements such as
<header>,<nav>, and<footer>, however, do not apply IDs or classes to them, since older browsers do not understand some of HTML5 elements by default and do not apply styling to them.<footer> <div class="site-footer"> ... </div> </footer> - Validation: if it is not correct, it may affect page performance, accessibility, and SEO. The W3C validator can be found here
-
Do not use inline CSS styles
-
Ultilize minified and compressed CSS file
-
Avoide to use duplicated styles
-
Even though CSS files are downloaded in parallel, combine all the CSS files if possible, it can reduce the http calls to server
-
Consider for browser compatibilities, do not style in a HTML5 element, use .header instead
<header> <div class="header"> ... </div> </header> -
Order CSS properties - grouped by type (from Nicolas Gallagher's Idiomatic CSS: http://nicolasgallagher.com/)
.selector { /* Positioning */ position: absolute; z-index: 10; top: 0; right: 0; /* Display & Box Model */ display: inline-block; overflow: hidden; box-sizing: border-box; width: 100px; height: 100px; padding: 10px; border: 10px solid #333; margin: 10px; /* Color */ background: #000; color: #fff /* Text */ font-family: sans-serif; font-size: 16px; line-height: 1.4; text-align: right; /* Other */ cursor: pointer; } -
Use modular CSS Name convention: BEM - The Block, Element, Modifier methodology
The following example is from ROBIN RENDLE https://css-tricks.com/bem-101/
/* Block component */ .btn {} /* Element that depends upon the block */ .btn__price {} /* Modifier that changes the style of the block */ .btn--orange {} .btn--big {} -
Avoid using !important
-
Combine all the script files
-
Do not use inline script if possible
-
Use minified javascript file
-
Only load the script is needed before page load
-
Use asynchronous method if possible, it will decrease page load time
AJAX Example: Use
XMLHttpRequest, it can get and send HTTP requestsa. Create http request - initialize
XMLHttpRequestvar xhr = new XMLHttpRequest();b. Use
open, it has three argumentsxhr.open('GET', "url", true);-
First argument: it has GET, POST, PUT, and DELETE. since we would like to get information, so we are using GET
-
Second argument: URL. Put the URL you would like to get data with
-
Third argument: requst asynchronous or synchronous. True means asynchronous request, it will make sure the web page is responsive and the remaining code is still running
c.
sendmethod, it will send the requestxhr.send(); -
-
Avoid using document.write
-
Avoid using global variables, wrap them in closures
-
Use fast DOM traversal with document.getElementById()
-
Use CSS classes instead of JavaScript for DOM animation
-
Keep the HTML clean and get rid of all those useless DIV and SPAN tags
-
Build DOM separately before adding it to the page
- Percentage-based grids
- Flexible scaled images
- CSS media queries
.example {...} @media(min-width: 480px) { .example { } } @media(min-width: 768px) { .example { } } @media(min-width: 1024px) { .example { } }
- Use .jpg for background image
- Use .svg or .png as logo