Timestamp inside clientlibs.min.css | Community
Skip to main content
devj81705801
Level 2
Nov 15, 2018 2:05 PM UTC
Solved

Timestamp inside clientlibs.min.css

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.
arunpatidar
arunpatidarAccepted solution
New Participant
Nov 15, 2018 5:04 PM UTC

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

9 replies

Feike_Visser1
Employee
Nov 16, 2018 9:59 AM UTC

I would strongly recommend this: Versioned ClientLibs

Translate
arunpatidar
New Participant
Nov 16, 2018 8:38 AM UTC

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.

Translate
Arun Patidar
devj81705801
Level 2
Nov 16, 2018 8:23 AM UTC

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

Translate
arunpatidar
New Participant
Nov 16, 2018 8:12 AM UTC

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

Translate
Arun Patidar
devj81705801
Level 2
Nov 16, 2018 7:42 AM UTC

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.

Translate
arunpatidar
arunpatidarAccepted solution
New Participant
Nov 15, 2018 5:04 PM UTC

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

Translate
Arun Patidar
smacdonald2008
Level 10
Nov 15, 2018 4:52 PM UTC

Have you looked at Versioned ClientLibs?

Versioned ClientLibs

Translate
devj81705801
Level 2
Nov 15, 2018 4:18 PM UTC

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

Translate
smacdonald2008
Level 10
Nov 15, 2018 2:54 PM UTC

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

Translate