王子1986
王子1986

Reputation: 3599

Thymeleaf put a dynamic parameter inside script tag

With thymeleaf and following code

<script th:src="@{/js/init.js}"></script>

I would like to make it like following in order to avoid browser caching for this file

<script th:src="@{/js/init.js?${minute}}"></script>

${minute} will be current time minute.

Upvotes: 0

Views: 2313

Answers (3)

RiZKiT
RiZKiT

Reputation: 2511

If you just want to provide versioned static files, you might try spring resource versioning. One possible solution using configuration only is described here https://stackoverflow.com/a/49040930.

Upvotes: 0

王子1986
王子1986

Reputation: 3599

I solve the question by use the following, it's a bit longer than expected.

<script th:src="@{/js/init.js(minute=${#dates.format(#dates.createNow(), 'mm')})}"></script>

Upvotes: 0

holmis83
holmis83

Reputation: 16604

Try:

<script th:src="@{/js/init.js(minute=${minute})}"></script>

Reference: Standard URL Syntax

Upvotes: 2

Related Questions