Expand my Community achievements bar.

SOLVED

Timestamp inside clientlibs.min.css

Avatar

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

Avatar

Correct answer by
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



Arun Patidar

View solution in original post

9 Replies

Avatar

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

Avatar

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

Avatar

Correct answer by
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



Arun Patidar

Avatar

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.

Avatar

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



Arun Patidar

Avatar

Level 2

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

Avatar

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.



Arun Patidar