This topic contains 3 replies, has 0 voices, and was last updated by silverriaz 8 years, 2 months ago.

  • Author
    Posts
  • #1813

    silverriaz

    Hello,

    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.

  • #1814

    david.smith

    Don’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.

  • #1815

    chanarbon

    Hi 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.

  • #1816

    silverriaz

    You guys are absolutely great! This is exactly what I was looking for.

You must be logged in to reply to this topic.