two snippets with the same name

  • 2
  • Question
  • Updated 2 years ago
  • Answered
Suppose I have two snippets with the same name.

(please hold all the WHY WOULD YOU EVER DO THAT!?! comments..  if the answer is favorable this will save a lot of time)

One snippet is on page, another is in a static resource.

Which will run first?

Does it depend on the order that they are entered in the builder?
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb

Posted 2 years ago

  • 2
Photo of Karen Waldschmitt

Karen Waldschmitt, Official Rep

  • 8,260 Points 5k badge 2x thumb
Matt~

In line snippet wins in a race against static resources.

Thanks!
Karen
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
Sweet. Thanks!
Photo of Barry Schnell

Barry Schnell, Champion

  • 18,076 Points 10k badge 2x thumb
Matt -

FYI on this issue that I posted about a month ago https://community.skuid.com/skuid/topics/resources-not-emitted-in-order-specified?rfm=1&topic_su....  

I'm still waiting on a reply but as I mention in the issue, the order specified in the builder SHOULD matter - but instead it behaves like "it depends" currently and its not documented.  As Karen mentions, I believe inline snippets will always get loaded after static resources with the current functionality.  That said, being able to specify order (in order to reliably predict) the exact order things will load is critical to proper functioning - especially when you might need to do something in an inline snippet that a static resource then relies on (which wouldn't even be possible today).

Short story - Keep an eye out on the other thread just in case anything changes (which it should IMHO:)).
Photo of Barry Schnell

Barry Schnell, Champion

  • 18,076 Points 10k badge 2x thumb
Oh yeah, forgot to ask - WHY WOULD YOU EVER DO THAT? ;)
Photo of Pablo Martinez

Pablo Martinez

  • 2,468 Points 2k badge 2x thumb
hahahahahahahhahahaa
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
Thanks, Barry. I'll keep an eye out.

I'm deploying an app to multiple customers who may need to customize some of the javascript functionality, and I'm trying to make it as modular as possible. In the current scenario, they can write their own inline snippet to override the stock functionality that I deploy in a static resource by using the same snippet name. Then if I deploy an update to the stock resource it won't override their customization.
Photo of Pablo Martinez

Pablo Martinez

  • 2,468 Points 2k badge 2x thumb
That's a good reason (better than I expected :p)
Photo of Barry Schnell

Barry Schnell, Champion

  • 18,076 Points 10k badge 2x thumb
Hey Matt - I was just kidding with that question :)  I could see reasons you would want to do this (e.g. a "derived" customization of base functionality).  Fortunately, even if the order resources are loaded changes (per the other post I linked to), your approach will still work as long as the customers snippet comes after the SR that you provided for them.  Pretty cool way to provide flexibility to your customers!
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
Ok, followup to this:

Suppose I have two snippets with the same name. One is in the ModuleJS static resource that skuid pulls in to all pages in that module. The other is in a static resource that's added declaratively to the page.

Which wins?
Photo of Karen Waldschmitt

Karen Waldschmitt, Official Rep

  • 8,260 Points 5k badge 2x thumb
Matt~

Sorry for the delayed response. The static resource added declaratively to the page wins. 

Karen
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
Thanks, Karen.
Photo of Matt Sones

Matt Sones, Champion

  • 31,478 Points 20k badge 2x thumb
Ok, another question in this vein...

Two snippets with the same name, in different static resources added declaritively to the page. If I am correctly understanding Barry's post here, the static resources are currently being loaded in the order that they are entered in the builder?

But what does that mean in this use case? Does the snippet in the first static resource win, or in the second?

Thanks!
Photo of Karen Waldschmitt

Karen Waldschmitt, Official Rep

  • 8,260 Points 5k badge 2x thumb
Matt~

So what ever is evaluated last wins when it comes to name conflicts.

Thanks!
Karen