Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Timestamp inside clientlibs.min.css

devj81705801
Level 2
Level 2

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 */

1 Accepted Solution
Arun_Patidar
Correct answer by
Community Advisor
Community Advisor

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

View solution in original post

0 Replies
smacdonald2008
Level 10
Level 10

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 O...

devj81705801
Level 2
Level 2

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

Arun_Patidar
Correct answer by
Community Advisor
Community Advisor

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

devj81705801
Level 2
Level 2

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.

Arun_Patidar
Community Advisor
Community Advisor

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

devj81705801
Level 2
Level 2

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

Arun_Patidar
Community Advisor
Community Advisor

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.