I'd like to use a JS tool, but it needs some additional files. The readme says I Should add a few files to the server. I tried by adding it in static resources and modifying part of the js tool so it could point to the files, but I still get error messages from the js tool.

This is where I changed the jsqrscanner.nocache.js file:

part of jsqrscanner I modified

And these are the static resources I added to Salesforce: static resources

Now I get this message when accessing the VF page: error console log

1 Answer 1


Merge fields do not work in static resource JavaScript files. They only work in a Visualforce page directly, as Visualforce will "patch" the correct value into the source code for the page.

You have a few basic choices here. You can (a) include all the script files in a single static resource, (b) use JavaScript in the main page before loading the scripts, or (c) combine the files into a single script.

For the first option, place all your JS files into a single folder on your computer, then turn that folder into a ZIP/Compressed Folder. In Windows, select multiple files, then right-click and choose Send To > Compressed Folder. Upload the resulting folder as a static resource, and you should be good to go:

$b = 'script1.js';
_b = 'script2.js';
// etc...

Use the original file names in the ZIP, you can actually use the code verbatim. This is likely the easiest option, and what I would recommend.

With the second option, you use merge fields in the main page, then load those values.

<apex:page ...>
    window.qrCode1resource = "{!$Resource.qrcode1}";
    window.qrCode2resource = "{!$Resource.qrcode2}";
    window.qrCode3resource = "{!$Resource.qrcode3}";
    window.qrCode4resource = "{!$Resource.qrcode4}";
    window.qrCode5resource = "{!$Resource.qrcode5}";
  <apex:includeScript value="{!$Resource.qrcodeMainScript}" />

And then in your main script file:

$b = window.qrCode1resource;
_b = window.qrCode2resource;
// etc...

Note that there are no "quotes" here, as these are variables, not strings.

With the third option, you'd copy-paste the scripts into a single file, assigning the values to local script variables, and then patch the code to just directly reference those local variables instead of external files. This takes slightly longer, but is ultimately more portable, as you don't need to deal with multiple files.

  • It works now. Thanks a lot!!!!
    – kiwi
    Jan 21, 2021 at 3:32

You must log in to answer this question.

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