0

I have a Spring boot app with a Thymeleaf template, that is supposed to load a css file and a javascript file. The CSS file loads, but the Javascript file doesnt, it does not even try to get it from the server. There is no HTTP request for the Javascript, but the requests for the CSS are visible. Where is my mistake?

I already tried putting the link for the javascript in the header next to the css but that made no difference.

My folder structure is as follows:

resources
-- static
---- bootstrap
------ css
---- js

Here the HTML:

<html xmlns:th="https://thymeleaf.org" lang="en" style="height: 100%;">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>Website Title</title>
  <link rel="stylesheet" type="text/css" th:href="@{/bootstrap/css/bootstrap_custom.css}" />
</head>
<body class="d-flex flex-column h-100">
  <script th:href="@{/js/main.js}" type="text/javascript"></script>
</body>
</html>

There is no error message, the tag for the javascript is simply ignored.

2
  • what does your script contain? Try to put some console.log in your script and check your dev tools console Commented May 18, 2019 at 10:31
  • 1
    Found the error: I wrote script th:href instead of th:src. A overdue nap has brought the solution. Commented May 18, 2019 at 10:51

2 Answers 2

2

Your script end tag is incomplete. It should be:

<script th:src="@{/js/main.js}" type="text/javascript"></script>
Sign up to request clarification or add additional context in comments.

1 Comment

Found the error: I wrote script th:href instead of th:src.
2

The tag should read

<script th:src[...]>

instead of

<script th:href[...]>

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.