+ Start a Discussion
David Zhu 8David Zhu 8 

Javascript in VF Page

We have an Service Cloud application using custom VF Pages. 
In the mostly used page, there are 1200 lines of Javascript and 300 lines of style setting in a 3000 lines VF page. I don't think it is the best practice at all.

Javascript uses Salesforce Remoting to interact with Salesforce class.
The following is a snippet.
Visualforce.remoting.Manager.invokeAction(
                    '{!$RemoteAction.CaseExtension.findVINs}',
                    query,
                    programQueryFilter,
                    typeOfCase,
                    function(lstresult, event){        
                        for (var n=0; n<lstresult.length; n++){
                            var result = {
                                value: lstresult[n].Id,
                                label: lstresult[n].VIN_Person__c, 
                                name: lstresult[n].Name, 
                                car: lstresult[n].Car__c,
                                person: lstresult[n].Person__c
                            };
                            data.push(result);
                        }
                        callback(data);
                    }
                );


On this page, it has different sections to display different information. Users use buttons to switch displayed sections.

Users are complaining, when switching the information section, some entered information is missing, or dropdown is not populated.

Could thie problem be related to the performance of Salesforce Remoting from Javascript?

What is the best practice to move javascript and styles into static resource?

Thanks,
David