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
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Why Splunk Customers Should Attend Cisco Live 2026 Las Vegas

Why Splunk Customers Should Attend Cisco Live 2026 Las Vegas     Cisco Live 2026 is almost here, and this ...

What Is the Name of the USB Key Inserted by Bob Smith? (BOTS Hint, Not the Answer)

Hello Splunkers,   So you searched, “what is the name of the usb key inserted by bob smith?”  Not gonna lie… ...

Automating Threat Operations and Threat Hunting with Recorded Future

    Automating Threat Operations and Threat Hunting with Recorded Future June 29, 2026 | Register   Is your ...