How to access Web Files over a stable URL without <anti-cache> value
In Using Web Files, it is explained how to create in a JSP or FTL a URL to a Web File by using the hst webfile tag, for example in FTL
<@hst.webfile var="link" path="/js/script.js" /> <script src="${link}" />
resulting in a URL in the form
/webfiles/<anti-cache>/js/script.js
The <anti-cache> part is changed whenever a Web File is changed : Because the URL changes when a web file changes, we can serve web files to the client (browser) with an 'Expires' header of one year (aka caching 'forever').
However, when you need a stable URL to access a Web File, for example because you request originates from some NodeJs server side application that does not 'know' the <anti-cache> value but just a fixed Web File URL, this can be achieved as follows:
Web Files Stable URLs
When you want stable URLs, you need to bootstrap a sitemap item below hst:default where the name of that sitemap item replaces the <anti-cache> value in the URL. Assume you want to access the script.js file from above over the URL
/webfiles/latest/js/script.js
then you need to bootstrap a sitemap item with the name latest below hst:default/hst:configurations/hst:sitemap/webfiles using the following YAML source definition:
definitions: config: /hst:hst/hst:configurations/hst:default/hst:sitemap/webfiles/latest: jcr:primaryType: hst:sitemapitem /_any_: jcr:primaryType: hst:sitemapitem hst:relativecontentpath: ${1}
After the above addition in the repository data, a rebuild and restart should result in the following web files sitemap items:
/hst:hst: /hst:configurations: /hst:default: /hst:sitemap: /webfiles: /_default_ : /_any_: /latest: /_any_:
and you should be able to access the script.js file via
/webfiles/latest/js/script.js