Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I include external javascript file using thymeleaf?

I'm using Spring Boot / MVC and learning Thymeleaf.

Let's say i have my scripts on another server.

https://staticserver.com/main.js

I've added the '//staticserver.com' portion to my model as jsLocation.

I want to do something on the lines of:

<script src="${jsLocation}/main.js"></script>

which would render

<script src="//staticserver.com/main.js"></script>

like image 618
Chinmay Avatar asked Jun 29 '26 09:06

Chinmay


2 Answers

<script th:src="|${jsLocation}/main.js|"></script>
like image 50
Flocke Avatar answered Jul 01 '26 04:07

Flocke


You can include external js file like below :

<script th:src="source to your external JS"></script> 

You can refer below thread for more details as your query also relates to model.

Thymeleaf external javascript file shares the module attributes with html file

like image 39
Alien Avatar answered Jul 01 '26 04:07

Alien



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!