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>

3 Answers 3

8
<script th:src="|${jsLocation}/main.js|"></script>
Sign up to request clarification or add additional context in comments.

2 Comments

I used this solution to drop my google api key into the places javascript library request <script th:src="|https://maps.googleapis.com/maps/api/js?key=${googleApiKey}&libraries=places|"></script>
It is very weird and ODD syntax. I don't understand why not defined like th:src="/my/script/path/${fname}"
4

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

Comments

2

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

<script th:src="@{/resources/static/js/fileName.js}"> </script>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.