WebApp resources

Static resources are stored in the /resource folder.

Generating URLs

URLs to resources are generated using the getResourceUrl function which is available when rendering templates.

// generates URL to 'info.pdf' stored in '/resource'
<img src="<%= getResourceUrl('info.pdf') %>" />

URL pattern: /webapp-files/<webappname>/<webappversion>/info.pdf

// generates URL to 'image.png' stored in '/resource/images'
<img src="<%= getResourceUrl('images/image.png') %>">

URL pattern: /webapp-files/<webappname>/<webappversion>/images/image.png


The AppResource utility is used to access resources within a WebApp.

// retrieve an instance of the appResource utility
var appResource = require('appResource');

Resources can be accessed in three different ways, where pathToResource is the path to the file in the resource folder.


Returns the resource as a UTF-8 based string.


Returns the resource as a JCR Node (sv:image or sv:file).


Returns the resource as a java.io.BufferedInputStream.

(function() {
   'use strict';

      router       = require('router'),
      appResource  = require('appResource');

   router.get('/', function(req, res) {
      var fileContentAsString = appResource.getContent('message.txt'),
         fileAsNode = appResource.getNode('pdf/info.pdf'),
         fileInputStream = appResource.getInputStream('images/cat.png');

      res.render('/', {message: fileContentAsString});