This topic contains 3 replies, has 0 voices, and was last updated by silverriaz 8 years, 2 months ago.
-
AuthorPosts
-
September 15, 2016 at 8:09 am #1813
silverriazHello,
If you take a module such as N/task, it doesn’t work with client scripts. If you load this module or a custom module that loads N/task, on Client side, the entire client script breaks without any error breaking all client side validations. If we do this the other way, say, load N/ui on a user event script, an error is thrown when the record is loaded.
The use case is that it’s hard to create a single library for a specific module and include them commonly in any type of script. Currently, I have to do modulex.js, modulex-server.js and modulex-client.js
If there is a possibility to conditionally load based on runtime context, I can combine 3 files to a single file.
Any ideas?
Riaz G
This is a cached copy. Click here to see the original post. -
September 15, 2016 at 9:47 am #1814
david.smithDon’t create one module but rather many. Only load the ones you need at the time of processing the code. Loading extra code that is not always used can cause performance or conflict issues. Try using the require[] to load what you need when you need it.
https://netsuite.custhelp.com/app/an…805/kw/require
Use the require() Function to achieve progressive loading of native SuiteScript 2.0 modules and custom modules. When you use the require() Function, dependencies are not loaded until they are needed. Use the require() Function to increase script performance.
-
September 19, 2016 at 10:17 pm #1815
chanarbonHi Riaz,
I agree with @david.smith’s reply. One of the pillars of 2.0 is to be able to run your script/business logic with the minimum amount of imports (modules) needed to improve the total performance of scripts. Similarly, you can do a require() within a define() e.g.
Code:
define([], function(){
function myinit(a){
if(a == 1){
require([“mylib”],function(mylib) {
console.log(“Initializing BaseApp”);
}
);
}
return {};
}
return {
init : myinit
};
});
Jarod Tavares replied on 02/17/2017, 02:10 PM: Unfortunately, if you use something like that example code while inspecting the context in a module, I find it triggers “Fail to evaluate script: All SuiteScript API Modules are unavailable while executing your define callback” when editing the calling module, even though it otherwise works fine.
-
September 20, 2016 at 5:48 am #1816
silverriazYou guys are absolutely great! This is exactly what I was looking for.
-
AuthorPosts
You must be logged in to reply to this topic.