Dashboards & Visualizations

RequireJS: load a custom script from the /appserver/static

npichugin
Path Finder

Hi splunkers,

One of my SimpleXML dashboards loads a JS script specified within <dashboard> tag. I want this script to load and use another shared .js file. I put them both into /appserver/static and tried to use RequireJS (the first calls "define(...)" function, and the second calls "require(['./first'], ...)" function). But all I get is a "Script error" in the JS console.

Is this possible at all? What should I do?

P.S. I know I can put the shared JS file name into the "script" attribute of the toplevel "dashboard" tag alongside with the main script, but is there any guarantee they'll be loaded sequentially and in the right order?

paramagurukarth
Builder

If You Just want to load two JS files to a simple-XML...
Give two script file name separated by comma...

script="yourUtil.js,yourPrimary.js"

yourUtil.js will be loader first and yuorPrimary.js will be loaded...
i.e.. in the same order as you define 🙂

0 Karma

helge
Builder

I can but agree. Having the app name in the URL is ugly and calling for future errors that are difficult to diagnose. There should be better support for building custom modules using the mechanism chose by Splunk (RequireJS).

araitz
Splunk Employee
Splunk Employee

I'm glad you got it to work. I couldn't agree more: require is hard to configure and debug, and it's hard to feel too confident about those paths staying consistent in the future. I'll ask the core team what we can do about it.

npichugin
Path Finder

That's what I did: I used the Firefox built-in inspector to see what actual scripts are being loaded.


GET http://myhost:8000/en-US/static/@182037/js/first.js
GET http://myhost:8000/en-US/static/@182037:8/app/myapp/second.js

The first one, of course, fails with 404. So I modified the second.js a bit: changed the "./first" to "../app/myapp/first".

Now it works, but feels like a fragile hack a bit. I'm not sure if this will work in future versions of Splunk at all. Any suggestions and comments are welcome.

npichugin
Path Finder

Hi araitz,
The exact error text I see in a browser console is:

Error: Script error
http://requirejs.org/docs/errors.html#scripterror

And this is reported on "config.js:6" -- definitely not my script.
The manual page that is referenced by this URL suggests that there may be a syntax error somewhere. I'm not sure if this is the case, though, as I just copy-pasted the 100% working piece of code and wrapped it in a define() call.
So, the error message itself is not of great help.

araitz
Splunk Employee
Splunk Employee

require.js can be a real bear to debug. The first thing to keep in mind is that there is a core require profile that's in $SPLUNK_HOME/share/splunk/search_mrsparkle/exposed/js/profiles/shared.js. Relative pathing might be difficult because of this profile.

Can you share the specific error/errors? Something about a mismatched anonymous define()?

0 Karma
Get Updates on the Splunk Community!

Index This | I am a number, but when you add ‘G’ to me, I go away. What number am I?

March 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...

What’s New in Splunk App for PCI Compliance 5.3.1?

The Splunk App for PCI Compliance allows customers to extend the power of their existing Splunk solution with ...

Extending Observability Content to Splunk Cloud

Register to join us !   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to ...