Has anyone used the DataTables.js library with the...
# suitescript
m
Has anyone used the DataTables.js library with their scripts, without using the CDN, but the library locally? Willing to share how you got it working?
w
It depends where you want to use it. You can load it into your filing cabinet then refer to it as a source library in something like a suitelet response using the url it generates on the file page.
n
or in your define using relative path to the file in your filecabinet. Not used that specific library but that's a general way to work.
j
I haven’t done this with DataTables.js but I’d done it with other “external” scripts that I’ve dumped into my file cabinet, like momentJS and lodash.
just treated it as a custom module and
define
as usual.
s
Do you not trust CDN?
m
@Shawn Talbert - CDN is fine, no issues there. Just a personal preference to use local when I can.
Thanks for the info everyone. DataTables says it’s ready for AMD use without modifications, but I think something with the NetSuite environment causes an issue trying to use it locally through the usual means. I think it needs to get access to jQuery and the global window object before NetSuite actually does its module import on the client side.
s
I'd definitely go for CDN for speed compared to NS's slow file cabinet access. You can try waiting to import that lib until later in the page loading process?
y
There are no issues as of now....i used both the way CDN & local as well..
m
If you are just looking to include it client side from CDN is probably the preferred method. Because otherwise I think you have to rewrite the URL anyway since a relative url won't work to my knowledge. You have to find the file record and get it's Netsuite url and replace it in the rendered page. If I am understanding what your trying to do. I had to do this for an app with built css, js and image assets, most resources I could inline using webpack, but there were still some assets that needed rewritten. I just put a check in the code if there were relative assets in the page template and then would replace all instances and save the file back so search and replace didn't have to happen for every page load. This slows down the load time of the first time the app loads after a new deployment and then all subsequent ones are quicker. Not my favorite way to do things but it seems to have worked reliably.