My FNZ Studio Version

Development Resources

Latest Update: 14.02.2022 |
Recipe
2024
2023
2022.2
2022.1
11
10
9
8
7

Problem

How do I generate URLs to access Resources?

Solution

Resource URLs

There are four ways to "address" Resources using URLs:

1: http://<host>/<contextPath>/resource/object/<resourceId>
2: http://<host>/<contextPath>/resource/object/<resourceId>/<fileName>
3: http://<host>/<contextPath>/resource/object/<resourceId>/<versionFilter>
4: http://<host>/<contextPath>/resource/object/<resourceId>/<versionFilter>/<fileName>

If you have to create an URL pointing to a Resource on the same system, you may of course omit the protocol and host name part and specify an absolute path instead:

/< contextPath>/resource/object/< resourceId>

1. Resource ID

The Resource ID <resourceId> is the only mandatory element in the URL.

2. File Name

If the URL doesn't contain a file name <fileName> (format 1 and 3), Appway creates a URL with a file name and redirects the client to this URL. It is therefore always faster to add a file name directly. You avoid an additional response/request cycle.

Note that the file name you specify in the URL doesn't have to correspond with the real file name of the Resource. The only relevant information in the URL is the Resource Id and the Version Filter. But some browsers may get into trouble if there is no file name or if the file name extension doesn't match the file content. Don't use a file name "image.gif" in an URL pointing to a Resource containing a JPEG image.

3. Version Filter

If the URL contains a Version Filter <versionFilter> in the path, this Version Filter is used to select the version of the Resource. If there is no Version Filter in the path, Appway checks if there is an HTTP parameter called "versionFilter".

If there is no Version Filter at all (neither as part of the path nor as parameter), Appway uses a "Latest Committed Filter" and therefore selects the newest committed version of the Resource. If there is no committed version of this Resource, a 404 HTTP error code ("file not found") is returned.

If there are two Version Filter definitions (one in the path and one as parameter), the Version Filter in the path is given precedence.

Adding a Version Filter to the URL path is also a save way to avoid caching problems in browsers. URLs with parameters are often handled differently and you may encounter unexpected effects. But if the Version Filter is part of the URL path, this looks to the browser like an ordinary sub-directory. Different versions of a Resource then look like files in different directories and therefore get cached individually.

4. Resource Archives

If a Resource is a ZIP archive file, you can access the files inside the archive directly using an URL. In order to be recognized as a ZIP file, the Resource must have a MIME-type set to application/zip. The URL used to access a file inside the archive consists of three parts:

  • The URL pointing to the Resource as described in the sections above.
  • An extra path element containing an exclamation mark: /!/ or /%21/
  • The path inside the archive file

Example:
There is a Resource with ID "mylib" and a MIME-type application/zip. The archive contains a file mylib.js in the subdirectory js. This is how the URL to access this file could look like:

http://<host>/<contextPath>/resource/object/mylib/%21/js/mylib.js

Appway unpacks the archive into a temporary directory <DataHome>/work/cache/resources/<VersionUUId>.

5. Place Holders

If the file name ends with .js or .css, Appway scans the response and replaces all occurrences of the place holders {VERSION_FILTER } and {CONTEXT_PATH }. {CONTEXT_PATH } is replaced with the context path of the web application. {VERSION_FILTER } is replaced with the Version Filter used to load the Resource (see above).

Note: Omit the extra space after the placeholder name and the closing bracket in your code.

An example:
A Resource GlobalStyles (file name styles.css) refers to another Resource BgImage (file name bg.gif) as background image. You would like to make sure that the Version Filter used to load the CSS file is also applied when loading the image file. The Version Filter has to be 'inherited' somehow. You can do this by referring to the image file like this:

body {
   background-image: url(/resource/object/BgImage/{VERSION_FILTER }/bg.gif);
}

If the CSS Resource is now loaded with a Head Filter, the image Resource is loaded with a Head Filter too:

URL to the CSS Resource:

http://www.numcom.com/resource/object/GlobalStyles/HeadFilter-false-permanent/styles.css

URL for the image Resource (inside the CSS code, results from replacing the place holders):

http://www.numcom.com/resource/object/BgImage/HeadFilter-false-permanent/bg.gif

This URL format is the default format generated by Screen components like HTML Head Link, HTML Head Script, Image or Resource Include; by Screen actions like 'Display Resource', and by the built-in function RESOURCEURL.

By the way: If you would like to open an Resource by entering the URL in the browser, you can instruct Appway to skip place holder replacement. To do this you have to add a parameter skipReplacement=true to the URL.

6 Automatic URL Generation

Whenever possible you should use Appway's built-in methods to generate URLs to Resources.

Function RESOURCEURL

There is a built-in function that may be used in Appway script code to generate the path part of an URL pointing to a Resource:

String $resourceId := 'GlobalCSS';
String $url := RESOURCEURL($resourceId);

The optional second function parameter is used to specify a Version Filter.

Screen Components

Some Screen components may use Resources. The Image component may be used to display an image saved as a Resource. The Screen action Display Resource may be used to show a Resource file in a new window. All these components and actions use the same methods to generate Resource URLs automatically.

© 2026 Appway AG. All Rights Reserved