0

I need to embed javascript directly into html page generated by Thymeleaf Something like:

<script th:include="../static/assets/generated/scripts.js"></script>

But this simple usage leads to SAXParseException...

Is there any easy way to switch off parsing of the th:included content? Or any other way how to embed content of resource int the result page?

3 Answers 3

1

I don't think that is possible out of the box. You could probably write an extension that can do it. Or maybe there is an existing one, but I couldn't find one right now.

Does it have to to be a separate JavaScript file? Can't you put your JavaScript code into a fragment and include it like any other fragment?

NB: Including JavaScript into your HTML file like that is usually bad web design und may be a sign that you have bigger problems and you haven't structured your code well. Why do you think you need to do that? Why can't you refer to an external script file?

Sign up to request clarification or add additional context in comments.

Comments

0

Thats not a Thymeleaf-Thing. It's classic html:

<script src="/assets/generated/scripts.js"></script>

1 Comment

I don't think that is what the OP wants.
0

In version 3.0, you can do it in this way

<script th:src="@{/webjars/jquery/dist/jquery.min.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.