Timestamp inside clientlibs.min.css | Community
Skip to main content
devj81705801
Level 2
November 15, 2018
Solved

Timestamp inside clientlibs.min.css

  • November 15, 2018
  • 9 replies
  • 3440 views

How can we add build time of clientlib.miin.js files inside it.

For example inside clientlib.min.js  and clientlib.min.css we want below lines

JS

window.build = "Sun Sep 06 2018 ";

CSS

/*! Build: "Sun Sep 06 2018 */

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by arunpatidar

Hi,

There is no OOTB way to update timestamp for JS or CSS.

But you can add a JCR Event listener which will execute whenever css or js file is created/modify under /etc/design/.... and delete corresponding minified file in /var/ folder if available it will make sure the file is always latest.

Or alternative you can update timestamp as soon as there is new update in /var/ folder

9 replies

smacdonald2008
Level 10
November 15, 2018

There is no AEM specific functionality that will let you do this. To get a time stamp into a JS or CSS, you need to add custom app logic.

html - How to append timestamp to the javascript file in <script> tag url to avoid caching - Stack Overflow

devj81705801
Level 2
November 15, 2018

So is there a way to check that clientlibs added to the page is of latest build and not cached?

As we include clientlibs using categories and page source have something like this

/etc/clientlibs/clientlibs.min.css

So how can we check if its of latest build or old build

smacdonald2008
Level 10
November 15, 2018

Have you looked at Versioned ClientLibs?

Versioned ClientLibs

arunpatidar
Community Advisor
arunpatidarCommunity AdvisorAccepted solution
Community Advisor
November 15, 2018

Hi,

There is no OOTB way to update timestamp for JS or CSS.

But you can add a JCR Event listener which will execute whenever css or js file is created/modify under /etc/design/.... and delete corresponding minified file in /var/ folder if available it will make sure the file is always latest.

Or alternative you can update timestamp as soon as there is new update in /var/ folder

Arun Patidar
devj81705801
Level 2
November 16, 2018

Is there a way we can read maven timestamp value inside js and css files.

In JSP we can do as per below link

How to display maven project version in your webapp | Vineet Manohar's blog

But same doesn't work for js and css as replace <token>PROJECT_VERSION</token> happens for JSP file only.

arunpatidar
Community Advisor
Community Advisor
November 16, 2018

yes, you can get timestamp in maven  Stamping Version Number and Build Time in a Properties File with Maven - DZone Java

You can try to execute a java program in maven build phase and try to do normal file read and write with replace token.

3 ways to run Java main from Maven | Vineet Manohar's blog

Arun Patidar
devj81705801
Level 2
November 16, 2018

Thats fine but I need the value in js and css file , not in Java file

arunpatidar
Community Advisor
Community Advisor
November 16, 2018

I meant to say Instead of running replace token plugin You can run java executable plugin in maven build and read your js and css file in that java program and append timestamp in css and js file using java code.

Arun Patidar
Feike_Visser1
Adobe Employee
Adobe Employee
November 16, 2018

I would strongly recommend this: Versioned ClientLibs