I'm using the above to access custom setting on the page. But when I move the script to static resources and try to access it from there the value is not being fetched. Any help is much appreciated thanks!

  • Is it being rendered blank? Or does the script still show {!$Setup.MyCustomSet__c.URL__c}?
    – NSjonas
    Aug 6, 2015 at 22:04

2 Answers 2


Static resources are... static. There is no pre or post processing of their contents. Instead of putting globals from Visualforce code in your javascript, try putting some JavaScript in your Visualforce code.


  1. Before your script loads, create some JavaScript bridging code:

        $Setup = window.$Setup || {};
        $Setup.MyCustomSet__c = $Setup.MyCustomSet__c || {};
        $Setup.MyCustomSet__c.URL__c = '{!$Setup.MyCustomSet__c.URL__c}';
  2. Now in your javascript (in a static resource) use the variables as if they were VF, without {!}

    function errorHandler() {

If the naming is consistent, your front-end team can pluck the values straight out of the JavaScript and nobody has to invent anything. Also has the benefit of masking variations due to namespace prefixes.

  • I'm not a great UI developer, Can you please explain what exactly does the code in the page mean/ does? I mean window.$setup = window.$setup || {} and the other 2 lines. Thanks!
    – cartman
    Aug 6, 2015 at 23:06
  • window.$Setup = window.$Setup || {} will "reference $Setup if it exists" or "initialize it". That way different page components can share stuff on $Setup and play nice together. @cartman Aug 6, 2015 at 23:28

You will need to pass this run-time value to your script as a parameter from the page. Dynamic values like this cannot be referenced directly in the Static Resource markup.

You've got quite a few options, here's a few:

  1. Pass the value as a parameter to a function.
  2. Set it as a member variable on an object that exists in the page.
    var MyThing = {}; MyThing.URL = '{!$Setup.MyCustomSet__c.URL__c}';
    Then in your script, you can reference MyThing.URL for the value

  3. Set it as a variable on the window object (or similar) and then have your Static Resource script reference it from there.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .