3

From a performance/maintenance point of view, is it better to write my custom modules with netsuite all as one big JS, or multiple segmented script files.

Steve Reeder
  • 980
  • 16
  • 42

2 Answers2

2

If you compare it with a server side javascript language, say - Node.js the most popular, every module is written into separate file.

I generally take the approach of Object oriented javascript and put each class in a separate file which helps to organise the code.

One of the approach you can take is in development keep separate files and finally merge all files using js minifier tool like Google closure compiler when you deploy your code for production usage which can give you best of both worlds, if you are really bothered about every nano/mini seconds of performance.

If you see SuiteScript 2.0 architecture, it encourages module architecture which is easier to manage as load only those modules that you need, and it is easier to maintain multiple code files i.e. one per module considering future enhancements, bug fixes and code reuse.

prasun
  • 7,073
  • 9
  • 41
  • 59
  • OK, sounds like multiple files might be the way to go – Steve Reeder Jan 07 '16 at 05:32
  • FYI, if you want to go `Google Closure Compiler` route there are tools available using grunt/gulp/ant which can automate this procedure to a certain extent – prasun Jan 07 '16 at 06:43
1

Performance can never be judge by the line count of your module. We generally maintain modules for maintaining the readability and simplicity of the code. It is a good practice to put all generic functionalities in to an Utility script and use it as a library across all the modules. Again it depends on your code logic and programming style. So if you want to create multiple segments of your js file for more readability I dont think its a bad idea.

Rockstar
  • 2,228
  • 3
  • 20
  • 39