This article covers a Bloomreach Experience Manager version 11. There's an updated version available that covers our most recent release.

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 as follows:

filename : myproject-default-sitemap-webfiles-latest.xml

<sv:node sv:name="latest" 
  xmlns:sv="http://www.jcp.org/jcr/sv/1.0">
  <sv:property sv:name="jcr:primaryType" sv:type="Name">
    <sv:value>hst:sitemapitem</sv:value>
  </sv:property>
  <sv:node sv:name="_any_">
    <sv:property sv:name="jcr:primaryType" sv:type="Name">
      <sv:value>hst:sitemapitem</sv:value>
    </sv:property>
    <sv:property sv:name="hst:relativecontentpath" sv:type="String">
      <sv:value>${1}</sv:value>
    </sv:property>
  </sv:node>
</sv:node>

and in hippo-extensions.xml you add:

<sv:node sv:name="myproject-default-sitemap-webfiles-latest">
  <sv:property sv:name="jcr:primaryType" sv:type="Name">
    <sv:value>hippo:initializeitem</sv:value>
  </sv:property>
  <sv:property sv:name="hippo:contentresource" sv:type="String">
    <sv:value>myproject-default-sitemap-webfiles-latest.xml</sv:value>
  </sv:property>
  <sv:property sv:name="hippo:contentroot" sv:type="String">
    <sv:value>/hst:hst/hst:configurations/hst:default/hst:sitemap/webfiles</sv:value>
  </sv:property>
  <sv:property sv:name="hippo:sequence" sv:type="Double">
    <sv:value>31000.1</sv:value>
  </sv:property>
</sv:node>

After the above addition in bootstrap files, 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
Did you find this page helpful?
How could this documentation serve you better?
On this page
    Did you find this page helpful?
    How could this documentation serve you better?