Skip to main content

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?

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); 

Perfect. That’s just what we need. Thanks.