+1. Rishi Solanki Manager, Enterprise Software Development HotWax Systems Pvt. Ltd. Direct: +91-9893287847 http://www.hotwaxsystems.com
On Fri, Jun 24, 2016 at 2:13 PM, Divesh Dutta < divesh.du...@hotwaxsystems.com> wrote: > +1 Amardeep. > > > Thanks > -- > Divesh Dutta. > > On Fri, Jun 24, 2016 at 12:50 PM, Amardeep Singh Jhajj < > amardeep.jh...@hotwaxsystems.com> wrote: > > > Hello everyone, > > > > Currently, OFBiz javascript code (except third party libraries) is not > > written with the best practices which can cause following problems - > > > > 1. Increases the code maintenance effort. > > 2. Impact page performance. > > 3. Present not good examples to new contributors which leads to C/P to > > various areas of js code. > > > > Here are things we should do for cleanup and improvements in js code. > > > > 1. Remove unused javascript code and files if any. > > 2. Use best practices for javascript coding to improve performance (I > have > > listed some of it below). > > 3. Move utility js functions to one js file. > > 4. Remove deprecated code and use latest. For ex: We are still using > > "language='javascript'" attribute at script tag which is deprecated a > years > > ago. > > 5. js should be loaded at bottom of the page, currently its in Header. > Its > > a tedious task now to move it into footer because we have lot of js code > > inline in ftls. > > 6. js should not be written inline, it should be enough generic to be in > > minimum number of files and have generic code for doing the common set of > > operations over DOM. > > 7. Currently our macros of rendering pages has inline scripts, they can > be > > moved to one macrorenderer.js with generic code as we can use classes, > ids > > and data-attributes for doing any operation over html DOM. > > 8. After all cleanup work, we can think of build tool (like grunt) for > > various javascript build tasks (minification, concatenation of files) if > > needed. Its just a thought. > > > > I know its a huge effort and need to be done carefully. So before doing > any > > major changes, I would like to start work with first 4 points. > > > > Here is the list of some best practices to start with: > > > > 1. Use [] Instead of New Array() > > 2. Long list of variables? Omit the "Var" keyword and use commas instead. > > 3. Reduce global variables > > 4. Use explicit blocks > > 5. Start blocks on the same line > > 6. Always, Always Use Semicolons - Having said that, this is a very bad > > practice that can potentially lead to much bigger, and harder to find, > > issues. > > 7. Optimize loops. Avoid calculating the length of array in for loop > > iteration. > > 8. Avoid multiple redundant jQuery DOM manupulation by saving reference > to > > any object. > > 9. Try to use meaningful comments. > > 10. Many more. > > > > Here are some links of best practices information- > > > > https://www.w3.org/wiki/JavaScript_best_practices > > http://www.codeproject.com/Articles/580165/JavaScript-Best-Practices > > https://developer.yahoo.com/performance/rules.html > > > > If everyone agrees, I would like to start on this work. > > > > Please let me know your thoughts on it. > > > > Thanks and Regards > > -- > > Amardeep Singh Jhajj > > >