Developing for Splunk Enterprise

What's the difference between these two requires: splunkjs/ready! VS splunkjs/mvc/simplexml/ready! ???


Hi guys,

I was wondering, since i searched here and didn't find an answer for this, if any of you can explain me the difference between using require splunkjs/ready! or using require splunkjs/mvc/simplexml/ready! ??

In which case I should use one instead of the other?

Thanks in advance.

0 Karma


The first one, splunkjs/ready!, ensures that all splunkjs libraries are loaded before our code is executed. The second one, splunkjs/mvc/splexml/ready!, ensures that all Simple XML dashboard elements are loaded, i.e. your panels, search managers and visualizations. See here for source and search for "In our JavaScript" to jump to that section.

The idea of both is to ensure your code runs after those two processes are finished, even if one of them takes a while longer, because usually your code won't work or may even create errors if they haven't finished.

Which one you need depends on what you intend to do in your code. If you want to work some behind the scenes magic without touching any of your visualizations, you should be good to go with the first one only. If you want to move around stuff on your dashboard by changing the DOM with jquery or if you want to use a custom visualization using data from a search manager, you should probably use the second one as well.

In my personal experience, using the two ready statements is not strictly necessary, as most code will run fine either way with just the first one (though I've run into problems if that's not there). It's just that sometimes it won't, and to avoid trouble because of not-yet-loaded dashboard elements (also to increase portability: you never know where your apps run, and just because it runs on your machine doesn't mean it runs everywhere), you should use the second one if you operate on dashboard elements as well. Unfortunately, this is just my personal experience and I can't really cite any other reliable sources apart from the one above - but I know I was confused about this at first, too, but I hope I could clear things up a little for you.

Don’t Miss Global Splunk
User Groups Week!

Free LIVE events worldwide 2/8-2/12
Connect, learn, and collect rad prizes
and swag!