I have a static resource that contains an angular.js module. Now i want to call, in this static resource, a javascript function that is located in a Visualforce Page.

Is it possible to use the Visualforce.remoting.Manager.invokeAction? If not, could one resolve this issue?

1 Answer 1


Its definitely doable .You will need to use window global object to resolve all merge fields and then use the object in your static resource .

Here is a simple hello world example

<html lang="en">
 <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
    <title>Javascript Tips</title>
        window.configSettings = {
                id : '{!$User.Id}',
                firstName : '{!$User.FirstName}',
                lastName : '{!$User.LastName}',
                uiThemeDisplayed : '{!$User.uiThemeDisplayed}', 
          remoteActions: {
                helloWorld : '{!$RemoteAction.TestController.helloWorld}',
   <apex:includeScript value="{!URLFOR($Resource.MyJavascriptFile)}"/>
  <div> ....</div>

apex class

public with sharing class TestController {  
 public static String helloWorld() { 
   return 'hello word' ;  

The Static Resource Script

(function (window) {     
  function(result, event) {
    if (event.status) {
    } else {
    {buffer: true, escape: true}
  • 2
    Excellent answer. for us non java folks this helps bridge a gap. Would make an excellent blog post.......
    – Eric
    Commented Mar 3, 2017 at 16:15
  • 1
    Ah nice, had wrote something similar, not better than yours though (still learning the best practices). With that it doesn't pollute window object directly.
    – Raul
    Commented Mar 3, 2017 at 16:37
  • 1
    @RahulSharma I loved the module pattern .Its great.The thing about Javascript is its changing so much .This is ES5 way of doing it .In ES6 we have classes and other ways to handle this polluting issues . Commented Mar 3, 2017 at 20:00

You must log in to answer this question.

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