Getting a published page's version at runtime from the broker database (Tridion 2011 Java)

Eleanor: 6 days ago

I'm in the process of implementing a modular JS/CSS system on our site and I'd like to introduce a cache buster ?v=1 query to the end of the file url's.

Due to the fact we use a runtime DCP to write out our header tags, I'm trying to fetch the CSS/JS pages version via the DCP and append it to the src.

Is it actually possible to do this by directly accessing the page in the broker DB with the Java API? Couldn't find any examples.

Any help appreciated,


Ryder: 6 days ago

First of all you won't be able to change anything into broker db via API and I would recommend not to do it either. The only way changes should go into broker db is via publish.

Having said that, for client side cache busting you can implement something like the below:

  1. Option 1:

When any css file is added to cms or a reference is added in content, you can use datetime stamp as the version for the fully qualified url as a query string param. This can be easily done using event system.

  1. Option 2:

Alternatively if you refer CSS from an external system or just have references which are fully qualified url's or relative url's, you can write a tbb to add datetime of modified time of the page/component as the cache buster to the url as a query string param during the publish process.

  1. Option 3:

If you are publishing the CSS files from Tridion and the application references the CSS and the need is to update the application references when the CSS is published, you can use a configuration component where you store the filename (CSS filename) and the datetime stamp and use it during the publish process to add the query string param for client side cache busting. The application will have to use this dynamic configuration component to update the references on wherever the CSS is referenced.

We use similar approach and have been using it without issues.