JavaScript Best Practice
- Modularizing the code – one function block for one activity
- Place Scripts at the Bottom of Your Page
- Use === Instead of ==
- Eva is Bad
- User JSON.Parse instead of eval
- Don't Use Short-Hand and always use simi colon
- Declare Variables within the scope and avoid declaring the variables within the “For Statement”
- Reduce Global variables or have them with the unique name space.
- Comment Your Code but don’t write stories
- Make sure the debugging comments are removed before moving to production
- Use {} Instead of New Object()
- Use [] Instead of New Array()
- Use “For in” statement to loop thru the Object
- Separate Content, JS & Styles
- Avoid heavy nesting of for loop especially while accessing DOM
- Keep DOM access to minimum
- Compress the JS file with the 3rd Party utility
- Avoid duplicate JS scripts/function being loaded
- Make AJAX Cacheable
- Use GET for AJAX Requests
- Don't Scale Images in HTML
- Use YSlow to optimize the code
- Better to validate the HTML as well as CSS for the compatibility
- Follow proper coding standards
HTML & CSS
- Declare the Correct DocType [may be xHTML DTD would be good]
- Always Close Your HTML Tags
- Never Use Inline Styles
- Place all CSS Files External Within the Head Tag
- All Images Require "Alt" Attributes
- Avoid hacks like Filters & expressions
- Load image using CSS Sprites (Optimize)
No comments:
Post a Comment