Custom Binary Link Generation
By default, binary links are generated like the following examples:
If you want to cache these binaries on the client and/or in intermediate proxies like squid, mod_cache, varnish or an intermediate CDN like akamai, but at the same time want to serve directly a new version when the binary gets changed, you can include the last modified timestamp of the binary resource in the URL. This is a well known and effective way to cache binaries : Instead of having short expires or pragma no-cache, cache them forever and change the URL in case the binary gets updated. To inject the last modified timestamp, you need to create a custom org.hippoecm.hst.core.linking.ResourceContainer bean in your SITE project.
For example, let's suppose we would like to generate the binary link URIs like the following examples instead:
Note that each link is prefixed by a timestamped path ( /_ht_1384250940000) in the above example. The timestamp can be retrieved from the jcr:lastModified property value of the target binary resource node. So whenever the binary resource node gets updated, the binary URL will change. This way, you can add an expires of 1 year (aka eternal) on the served binaries, since a served binary URL will never change.
Here are example steps with an example implementation and configuration to fulfill this scenario.
1. Implement a custom ResourceContainer
Here's an example implementation. This simply overrides AbstractResourceContainer and prefix the binary link path info when generating links. And it simply removed the prefix when resolving the resource node from the path afterward.
2. Configure the custom ResourceContainer
Now, in order to enable your custom ResourceContainer, you should add an XML file under src/main/resources/META-INF/hst-assembly/overrides/ folder in your SITE project. e.g., src/main/resources/META-INF/hst-assembly/overrides/custom-resource-containers.xml
3. Test
Now, visit your SITE and see how binary links are generated.