How best to share snippets across pages?

  • 2
  • Question
  • Updated 5 years ago
  • Answered
What's the best way to share snippets across our pages? We have all of our inline Javascript in a static resource, which is nice and neat, but our snippets are currently sitting within each page as a local resource. Should we extract the snippets out to our static resource and wrap them in the registerSnippet construct?
Photo of Glenn Elliott

Glenn Elliott, Champion

  • 7,738 Points 5k badge 2x thumb

Posted 5 years ago

  • 2
Photo of Zach McElrath

Zach McElrath, Employee

  • 49,262 Points 20k badge 2x thumb
Short answer: yes :)

Long answer: extract the snippets into the StaticResource. Every JavaScript Resource of type "Inline (Snippet)" can be refactored into a StaticResource like this:



(function(skuid) {

skuid.snippet.registerSnippet('SNIPPET_1_NAME',function(){
SNIPPET_1_BODY
});

skuid.snippet.registerSnippet('SNIPPET_2_NAME',function(){
SNIPPET_2_BODY
});

})(skuid);

Photo of Glenn Elliott

Glenn Elliott, Champion

  • 7,738 Points 5k badge 2x thumb
Perfect. That's just what we need. Thanks.