2

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>

Chinmay
  • 4,726
  • 6
  • 29
  • 36

3 Answers3

6
<script th:src="|${jsLocation}/main.js|"></script>
Flocke
  • 764
  • 6
  • 14
3

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

Alien
  • 15,141
  • 6
  • 37
  • 57
1

if your js file in /resources/static/js/

<script th:src="@{/resources/static/js/fileName.js}"> </script>
sangeun jo
  • 37
  • 9