Has anybody successfully implemented dynamic modul...
# suitescript
m
Has anybody successfully implemented dynamic module detection + loading? Consider you want to load the same library client side and server side, but includes a downstream module that includes
N/cache
. I have tried
require.defined("N/cache")
,
require.specified("N/cache")
, but these checks seem to fail server side. I have tried asynchronous module loading with fallback, but haven't figure out a method for this that would seem reliable across different script types. How I want it to work is if
N/cache
is not available then load the callback function that was passed directly. But server side it would detect that
N/cache
is available and utilize caching.
b
detect if you are running serverside or clientside instead of trying to detect if N/cache is available
the usual for javascript is checking for the window global
m
That makes sense. I was looking for something more generic where I wouldn't have to track contexts but rather detect availability. But I think there is a secondary concern now that I have run into that will probably mean it's not a path I want to go down. That is that require asynchronously loads the modules and these modules it would be called in are used pretty widely and I was looking for a way to not have to update all the places it's called. I am thinking now I will just pass
N/cache
in the calling script where I want and it just becomes an optional parameter in the function this would maintain backwards compatibility and I could just update where I think it's more critical to maintain caching.