title: How can I use <h:outputScript /> with a remote file?
body: <p>I have a server dedicated for static contents so I don't want to use the resources dir for storing javascript files but I don't want to stop using the <code>&lt;h:outputScript /&gt;</code> tag.</p>
  
  <p>How can I make that tag generate a link to my static server where the files are located instead of <strong>RES_NOT_FOUND</strong>. I don't even need JSF to check if the files are there...</p>
  
  <p>I tried: <code>&lt;h:outputScript name="#{requestBean.staticURL}/javascript.js"/&gt;</code></p>
  
  <p>To generate: <code>&lt;script type="text/javascript" src="http://static.server.com/javascript.js"&gt;&lt;/script&gt;</code></p>
  
  <p>But it generates: <code>&lt;script type="text/javascript" src="RES_NOT_FOUND"&gt;&lt;/script&gt;</code></p>
  
  <p>What can I do?</p>
  
  <p><strong>SOLUTION:</strong>
  Daniel pointed me to a nice solution!</p>
  
  <p>I've downloaded the Omnifaces's source code and modified the <code>org.omnifaces.resourcehandler.CDNResourceHandle.createResource(String resourceName, String libraryName)</code> method to:</p>
  
  <pre><code>public Resource createResource(String resourceName, String libraryName) {
      final Resource resource = wrapped.createResource(resourceName, libraryName);
  
      if (cdnResources == null) {
          return resource;
      }
  
      String resourceId = ((libraryName != null) ? libraryName + ":" : "") + resourceName;
  
      String path = cdnResources.get(resourceId);
  
      if(path == null){
          if(libraryName != null){
              resourceId = libraryName + ":%";
              path = cdnResources.get(resourceId);
              if(path == null){
                  return resource;
              }
              path += "/"+resourceName;
          }
          else return resource;
      }
  
      final String requestPath = path;
  
      return new ResourceWrapper() {
  
          @Override
          public String getRequestPath() {
              return requestPath;
          }
  
          @Override
          public Resource getWrapped() {
              return resource;
          }
      };
  }
  </code></pre>
  
  <p>With this change I can add this to my <strong>web.xml</strong> file</p>
  
  <pre><code>&lt;context-param&gt;
      &lt;param-name&gt;org.omnifaces.CDN_RESOURCE_HANDLER_URLS&lt;/param-name&gt;
      &lt;param-value&gt;
          somelib2:%=http://cdn.example.com/somelib2,
          js/script1.js=http://cdn.example.com/js/script1.js,
          somelib:js/script2.js=http://cdn.example.com/somelib/js/script2.js,
          otherlib:style.css=http://cdn.example.com/otherlib/style.css,
          images/logo.png=http://cdn.example.com/logo.png
     &lt;/param-value&gt;
  &lt;/context-param&gt;
  </code></pre>
  
  <p>Notice the <code>somelib2:%=http://cdn.example.com/somelib2</code>, this will point any resource in <strong>somelib2</strong> library to the relative path in <strong>http://cdn.example.com/somelib2</strong>, for example:</p>
  
  <p><code>&lt;h:outputScript name="js/myjs.js" library="somelib2" /&gt;</code></p>
  
  <p>will output:</p>
  
  <p><code>&lt;script type="text/javascript" src="http://cdn.example.com/somelib2/js/myjs.js"&gt;&lt;/script&gt;</code></p>
  
  <p>This works with <code>&lt;h:outputScript /&gt;&lt;h:outputStylesheet /&gt;&lt;h:graphicImage /&gt;</code>, anything that use resources;</p>